0% found this document useful (0 votes)
66 views6 pages

Os Experiment 2

The document outlines a series of experiments related to operating systems, focusing on hardware and software requirements, system calls for process and file management, and CPU scheduling policies. It includes theoretical explanations and example programs for various system calls, such as fork(), open(), read(), and write(). Additionally, it covers concepts like file management, resource allocation graphs, and provides answers to common questions about processes and system calls.

Uploaded by

fungamerz787
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views6 pages

Os Experiment 2

The document outlines a series of experiments related to operating systems, focusing on hardware and software requirements, system calls for process and file management, and CPU scheduling policies. It includes theoretical explanations and example programs for various system calls, such as fork(), open(), read(), and write(). Additionally, it covers concepts like file management, resource allocation graphs, and provides answers to common questions about processes and system calls.

Uploaded by

fungamerz787
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

INDEX

PAGE NO. DATE OF DATE OF


S.NO. EXPERIMENT
EXPERIMENT SUBMISSION
SIGNATURE
Study of Hardware and
Software requirements of
different Operating Systems
1
(UNIX, LINUX, WINDOWS
XP and Windows 7/8)

Execute various UNIX System


Calls for
i. Process
2
Management
ii. File Management
iii. I/O System Calls
Implement CPU
Scheduling Policies
i. SJF
3
ii. Priority
iii. FCFS
iv. Multi-Level
Implement file storage
allocation technique:
4 i. Contiguous
ii. Linked –list
iii. Indirect allocation
Implement contiguous
allocation technique
5 i. Worst-Fit
ii. Best-Fit
iii. First-Fit
Calculation of external and
internal fragmentation
i. Free space list of blocks
6 from system
ii. List process file from
the system

Implementation of
compaction for the
continually changing
7
memory layout and
calculate total movement of
data
Implementation of resource
allocation graph
8 (RAG)Implementation
of Banker s ‟ algorithm

Implementation of
9
Banker’s algorithm
Conversion of resource
allocation graph (RAG) to
wait for graph (WFG) for each
10
type of method used
for storing graph.
EXPERIMENT – 2
Objective – Execute various system calls for
i. Process Management
ii. File Management
iii. Input/Output System Calls
Theory –

1. Process Management
Process management uses certain system calls. They are explained below.
1. To create a new process – fork () is used.
2. To run a new program = exec () is used.
3. To make the process to wait = wait () is used.
4. To terminate the process – exit () is used.
5. To find the unique process id – getpid () is used.
6. To find the parent process id – getppid () is used.
7. To bias the currently running process property – nice () is used.

2(i) Example program for example of fork ()

Figure: Flow of fork () system call

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main () {
int i =10;
int pid;
pid=fork ();
if (pid==0) {
for (i=0; i < 999999; i++) {
sleep (2);
printf (" from Child process %d\n", i);
}
}
else {
for (i=0; i < 999999; i=i+2){
sleep (2);
printf (" from Parent process %d\n", i);
}
}
return 0;
}
Output 2(i)

2. File Management

There are four system calls for file management,


1. open ():system call is used to know the file descriptor of user-created files. Since read
and write use file descriptor as their 1st parameter so to know the file descriptor open()
system call is used.
2. read ()system call is used to read the content from the file. It can also be used to read
the input from the keyboard by specifying the 0 as file descriptor.
3. write (): system call is used to write the content to the file.
4. close ():system call is used to close the opened file, it tells the operating system that you
are done with the file and close the file.
2(ii). Example program for file management
#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<stdio.h>
int main() {
int n,fd;
char buff[50];
printf("Enter text to write in the file:\n");
n= read(0, buff, 50);
fd=open("file",O_CREAT | O_RDWR, 0777);
write(fd, buff, n);
write(1, buff, n);
int close(int fd);
return 0;
}
Output 2(ii)

3. Input/Output System Calls

Basically there are total 5 types of I/O system calls:


 Create: Used to Create a new empty file.
 open: Used to Open the file for reading, writing or both.
 close: Tells the operating system you are done with a file descriptor and Close the file
which pointed by fd.
 read: From the file indicated by the file descriptor fd, the read() function reads cnt bytes
of input into the memory area indicated by buf. A successful read() updates the access
time for the file.
 write: Writes cnt bytes from buf to the file or socket associated with fd. cnt should not
be greater than INT_MAX (defined in the limits.h header file). If cnt is zero, write()
simply returns 0 without attempting any other action.
2(iii) Example program for Input/output System Calls
main(){
char c;
int a=1, i;
while (a != 0) {
read(0, &a, 3);
i=a;
write(1, &i, 3);
write(1, "\n", 1);
}
}

Output 2(iii)

.
VIVA QUESTION :

a. What is computer process?

Ans. A computer process includes:

1. Program code – the actual instructions to be executed.


2. Memory – space to store code, variables, and temporary data.
3. CPU state – like registers and the current instruction.
4. Resources – files, network connections, etc., that the process is using.

b. What do you understand by file management?

Ans. File management is the way a computer system handles files—like creating, naming, storing,
organizing, retrieving, and protecting them.

It’s part of the Operating System (OS), and it's super important because it helps users and programs access
data easily and efficiently.

c. Explain system calls?


Ans. A system call is a way for a program to request a service from the operating system (OS).

User programs can’t directly access hardware or critical OS functions (like memory or file systems), so they
use system calls to "ask" the OS to do things on their behalf

You might also like