Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Fr.

CRCE Operating Systems Lab 2023-2024

Fr. Conceicao Rodrigues College of Engineering


Department of Computer Engineering

Student’s Roll No 9963


9980 Students Name SOHAM GAVAS
Aashish Mhaske

Date of 16/2/24 SE Computer – Div BB


Performance

Aim: To study Process and File Management System Calls


Lab Outcome:
CSL403.1: Demonstrate basic Operating system Commands, Shell scripts, System Calls
and API wrt Linux.

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.

d) Explain fork(), getpid(), getppid(),wait() and waitpid() with syntax.


Ans:
● fork():

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():

getpid() returns the process ID of the calling process.


Syntax: pid_t getpid();

● getppid():

getppid() returns the process ID of the parent of the calling process.


Syntax: pid_t 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);

(2) File related system calls


a) Program to copy contents of one file (source) to another file (destination). Finally
displaying contents of destination file.
b) 2. Explain creat(), open(), close(), read() and write() with syntax.
Ans:
● creat():

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():

close() is a system call used to close an open file descriptor.


Syntax: int close(int fd);

● 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/

On time Knowledge of Implementation Total (10)


Submission(2) Topic(4) and
Demonstraion(4)

Signature of Date of Submission


Faculty

You might also like