OS Exp 3
OS Exp 3
OS Exp 3
Problem Statements:
(1.) Process related System Calls.
a) Create a child process in Linux using the fork system call. From the child process obtain
the process ID of both child and parent by using getpid and getppid system call.
b) Explore wait and waitpid before termination of process.
c) Explain ps command and output in detail. What is Zombie and Orphan Process? Show the
output.
Ans: The ps command in Unix-like operating systems (such as Linux) is used to provide
information about currently running processes. It stands for "process status." The output of
the ps command provides various details about processes running on the system.
Common options:
-e: Selects all processes.
-f: Produces a full listing.
-u <user>: Selects processes owned by a specific user.
-aux: Displays all processes in a detailed listing.
Output columns:
PID (Process ID): The unique identifier assigned to each process by the operating system.
TTY (Controlling terminal): The terminal associated with the process. If it's shown as ?, the
process is not associated with any terminal.
STAT (Process state): Indicates the current state of the process (e.g., R for running, S for
sleeping, Z for zombie).
TIME (CPU time): The amount of CPU time consumed by the process.
COMMAND (Command and arguments): The name of the command or program being
executed, along with its arguments.
fork() is a system call used for creating a new process, which is called the child process,
which runs concurrently with the process that makes the fork() call, which is known as the
parent process.
Syntax: pid_t fork();
Fr. CRCE Operating Systems Lab 2023-2024
● getpid():
● getppid():
● wait():
wait() causes the calling process to block until one of its child processes exits or a signal is
received.
Syntax: pid_t wait(int *status);
● waitpid():
waitpid() suspends execution of the calling process until a child specified by pid argument
has changed state.
Syntax: pid_t waitpid(pid_t pid, int *status, int options);
creat() is a system call used to create a new file or open an existing file for writing only. If the
file already exists, it will be truncated to zero length.
Syntax: int creat(const char *pathname, mode_t mode);
● open():
open() is a system call used to open or create a file and returns a file descriptor.
Syntax: int open(const char *pathname, int flags, mode_t mode);
● close():
● read():
read() is a system call used to read data from an open file descriptor into a buffer.
Syntax: ssize_t read(int fd, void *buf, size_t count);
Fr. CRCE Operating Systems Lab 2023-2024
● write():
write() is a system call used to write data from a buffer to an open file descriptor.
Syntax: ssize_t write(int fd, const void *buf, size_t count);
References:
https://www.geeksforgeeks.org/fork-system-call/
https://www.geeksforgeeks.org/getppid-getpid-linux/
https://www.geeksforgeeks.org/wait-system-call-c/
https://www.geeksforgeeks.org/zombie-and-orphan-processes-in-c/
https://www.geeksforgeeks.org/input-output-system-calls-c-create-open-close-read-write/