Os Lab Manual
Os Lab Manual
Os Lab Manual
CS2204L
Operating Systems
Laboratory Manual
Computer Engineering
© JSPM Group of Institutes, Pune. All Rights Reserved. All the information in this
Course Manual is confidential. Participants shall refrain from copying, distributing,
misusing or disclosing the content to any third parties any circumstances whatsoever.
1
Table of Contents
Sr . No. Topic Page. No.
A. Vision, Mission 3
C. PSOs 5
F. List of Experiments
1 Write a program that uses the fork system call to create a child process& 9-12
display its process ID.
2 Simulation of Scheduling algorithm. a) FCFS b) SJF c) RR. 13-16
3 Write a Program For Inter Process Communication using Pipe. 17-19
4 Write a Program to simulate solution to classical process synchronization 23-25
problems:
a) Dining Philosophers, b) Producer – Consumer, c) Readers – Writers.
5 Write a Program to simulate page Replacement algorithm. a) FIFO b) LRU 26-28
c) optimal.
6 Write a Program for File allocation Methods. a) Continuous b) Linked c) 29-30
Indexed.
7 Write a Program to simulate disk Scheduling Algorithm. a) FCFS b) SSTF c) 31-34
SCAN d) CSCAN e) LOOK.
8 To Implement UNIX System call, CP and CAT. 35-38
9 To Study and Implementation of Advance commands and filters of Linux.
2
Vision of Department
To create quality computer professionals through an excellent academic
environment.
Mission of Department
1. To empower students with the fundamentals of Computer Engineering
for being successful professionals.
2. To motivate the students for higher studies, research, and
entrepreneurship by imparting quality education.
3. To create social awareness among the students.
PEO II Graduate shall exhibit disciplinary skills to resolve real life problems.
PEO III Graduate shall evolve as professionals or researchers and continue to learn
emerging technologies.
3
Program Outcomes
Engineering Graduates will be able to:
1. Engineering knowledge: Apply the knowledge of mathematics, science,
engineering fundamentals, and an engineering specialization to the solution of complex
engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological change.
4
Program Specific Outcomes (PSO) addressed by the Course:
5
CO Description
CO PO1 PO2 PO3 PO4 PO5 PO PO7 PO8 PO9 PO PO PO PSO PSO PSO
6 10 11 12 1 2 3
CS2108 CO1 2 2 2 2 1 1 2 2 1
Operating
System Lab
CO2 2 2 2 2 1 1 2 2 1
CO3 2 2 2 2 1 1 2 2 1
CO4 2 2 2 2 1 1 2 2 1
CO5 2 2 1 1 2 2 1
Average Mapping 2 2 2 2 1 1 2 2 1
6
7
8
EXPERIMENT NO: 01
Write a program that uses the fork system call to create a child process& display its process
ID.
1. Title: Write a program that uses the fork system call to create a child process& display its
process ID.
2. Objectives:
- To understand concept of process
- To create child process using fork system call
3. Problem Statement:
Write a Program to create A Process using fork.
4. Outcomes:
After completion of this assignment students will be able to:
- Understand the concept fork
- Understand how to code
-
5. Software Requirements:
Linux OS
6. Hardware Requirement:
7. Theory Concepts:
Fork system call is used for creating a new process, which is called child process, which runs
concurrently with the process that makes the fork() call (parent process). After a new child process is
created, both processes will execute the next instruction following the fork() system call. A child
process uses the same pc(program counter), same CPU registers, same open files which use in the
parent process It takes no parameters and returns an integer value. Below are different values returned
by fork()
9
fork (); // Line 1
fork (); // Line 2
fork (); // Line 3
10
So there are total eight processes (new child processes and one original process).
If we want to represent the relationship between the processes as a tree hierarchy it would be the following:
The main process: P0
Processes created by the 1st fork: P1
Processes created by the 2nd fork: P2, P3
Processes created by the 3rd fork: P4, P5, P6, P7
P0
/ | \
P1 P4
P2
/ \ \
P3 P6 P5
/
P7
8. Conclusion:
Thus, I have studied how to create process using fork system call
References:
R1. Operating Systems: Internals and Design Principles. William Stallings.
R2. Operating System: A Design-oriented Approach. Charles Patrick Crowley
11
EXPERIMENT NO: 02
2. Objectives:
- To understand CPU scheduling algorithm
3. Problem Statement:
To write a c program to simulate the CPU scheduling algorithm First Come First Serve (FCFS)
4. Outcomes:
- After completion of this assignment students will be able to:
- Understand the concept CPU scheduling algorithm First Come First Serve (FCFS)
5. Software Requirements:
Linux OS
6. Hardware Requirement:
7. Theory Concepts:
To calculate the average waiting time using the FCFS algorithm first the waiting time of the first
process is kept zero and the waiting time of the second process is the burst time of the first process
and the waiting time of the third process is the sum of the burst times of the first and the second
process and so on. After calculating all the waiting times the average waiting time is calculated as
the average of all the waiting times. FCFS mainly says first come first serve the algorithm which
came first will be served first.
8. ALGORITHM:
12
Step 6: Calculate a) Average waiting time = Total waiting Time / Number of process
b) Average Turnaround time = Total Turnaround Time / Number of process
Step 7: Stop the process
DESCRIPTION:
To calculate the average waiting time in the shortest job first algorithm the sorting of
the process based on their burst time in ascending order then calculate the waiting time of
each process as the sum of the bursting times of all the process previous or before to that
Process.
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU
burst time
Step 4: Start the Ready Q according the shortest Burst time by sorting according to
lowest to highest burst time.
Step 5: Set the waiting time of the first process as ‗0‘ and its turnaround time as its
burst
Time.
Step 6: Sort the processes names based on their Burt time
Step 7: For each process in the ready queue,
Calculate
a) Waiting time(n)= waiting time (n-1) + Burst time (n-1)
b) Turnaround time (n)= waiting time(n)+Burst time(n)
Step 8: Calculate
c) Average waiting time = Total waiting Time / Number of process
d) Average Turnaround time = Total Turnaround Time / Number of
process Step 9: Stop the process
DESCRIPTION: To aim is to calculate the average waiting time. There will be a time slice, each
process should be executed within that time-slice and if not it will go to the waiting state so first
check whether the burst time is less than the time-slice. If it is less than it assign the waiting time to
the sum of the total times. If it is greater than the burst-time then subtract the time slot from the
actual burst time and increment it by time-slot and the loop continues until all the processes are
13
Completed.
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue and time quantum (or)
time slice
Step 3: For each process in the ready Q, assign the process id and accept the CPU
burst time
Step 4: Calculate the no. of time slices for each process where No. of time slice for
process (n) = burst time process (n)/time slice
Step 5: If the burst time is less than the time slice then the no. of time slices =1.
Step 6: Consider the ready queue is a circular Q, calculate a) Waiting time for
process (n) = waiting time of process(n-1)+ burst time of process(n-1 ) + the time
difference in getting the CPU from process(n-1) b) Turnaround time for process(n) =
waiting time of process(n) + burst time of process(n)+ the time difference in getting
CPU from process(n).
Step 7: Calculate c) Average waiting time = Total waiting Time / Number of process
d) Average Turnaround time = Total Turnaround Time / Number of process
Step 8: Stop the process
8. Conclusion:
Thus we have successfully implemented Scheduling algorithm
References:
R1. Operating Systems: Internals and Design Principles. William Stallings.
R2. Operating System: A Design-oriented Approach. Charles Patrick Crowley
14
EXPERIMENT NO: 03
1. Title:
2. Objectives:
-To learn Inter Process Communication using Pipe.
3. Problem Statement:
Write a Program For Inter Process Communication using Pipe.
4. Outcomes:
After completion of this assignment students will be able to:
- Understand the Programming language of Java
- Understand the concept communication between processes.
5. Software Requirements:
Linux OS,
6. Hardware Requirement:
7. Theory Concepts:
Interprocess communication is the mechanism provided by the operating system that allows processes
to communicate with each other. This communication could involve a process letting another process
know that some event has occurred or the transferring of data from one process to another.
A diagram that illustrates interprocess communication is as follows −
15
Synchronization is a necessary part of interprocess communication. It is either provided by the interprocess
control mechanism or handled by the communicating processes. Some of the methods to provide
synchronization are as follows −
Semaphore
A semaphore is a variable that controls the access to a common resource by multiple processes. The
two types of semaphores are binary semaphores and counting semaphores.
Mutual Exclusion
Mutual exclusion requires that only one process thread can enter the critical section at a time. This is
useful for synchronization and also prevents race conditions.
Barrier
A barrier does not allow individual processes to proceed until all the processes reach it. Many parallel
languages and collective routines impose barriers.
Spinlock
This is a type of lock. The processes trying to acquire this lock wait in a loop while checking if the lock
is available or not. This is known as busy waiting because the process is not doing any useful operation
even though it is active.
Pipe
A pipe is a data channel that is unidirectional. Two pipes can be used to create a two-way data channel
between two processes. This uses standard input and output methods. Pipes are used in all POSIX
systems as well as Windows operating systems.
Socket
The socket is the endpoint for sending or receiving data in a network. This is true for data sent between
processes on the same computer or data sent between different computers on the same network. Most of
the operating systems use sockets for interprocess communication.
File
A file is a data record that may be stored on a disk or acquired on demand by a file server. Multiple
processes can access a file as required. All operating systems use files for data storage.
Signal
Signals are useful in interprocess communication in a limited way. They are system messages that are
sent from one process to another. Normally, signals are not used to transfer data but are used for remote
commands between processes.
Shared Memory
Shared memory is the memory that can be simultaneously accessed by multiple processes. This is done
so that the processes can communicate with each other. All POSIX systems, as well as Windows
operating systems use shared memory.
Message Queue
16
Multiple processes can read and write data to the message queue without being connected to each other.
Messages are stored in the queue until their recipient retrieves them. Message queues are quite useful
for interprocess communication and are used by most operating system
Conclusion:
Thus we have successfully implemented interprocess communication
References:
R1. Operating Systems: Internals and Design Principles. William Stallings.
R2. Operating System: A Design-oriented Approach. Charles Patrick Crowley
17
EXPERIMENT NO: 04
Write a Program to simulate solution to classical process synchronization problems:
a) Dining Philosophers,
b) Producer – Consumer,
c) Readers-Writers
1. Title:
Write a Program for Inter Process Communication using Pipe.
2. Objectives:
-To learn Inter Process Communication using Pipe.
1. Problem Statement:
Write a Program for Inter Process Communication using Pipe.
• Outcomes:
After completion of this assignment students will be able to:
- Understand the Programming language of Java
- Understand the concept communication between processes.
• Software Requirements:
Linux OS,
4. Hardware Requirement:
- 4GB RAM ,500GBHDD
5. Theory Concepts:
Dining-philosopher:
The dining philosopher's problem is the classical problem of synchronization which says that five philosophers
are sitting around a circular table and their job is to think and eat alternatively. A bowl of noodles is placed at the
center of the table along with five chopsticks for each of the philosophers. To eat a philosopher needs both their right
and a left chopstick. A philosopher can only eat if both immediate left and right chopsticks of the philosopher is
available. In case if both immediate left and right chopsticks of the philosopher are not available then the philosopher
puts down their (either left or right) chopstick and starts thinking again.
Void Philosopher
{
while(1)
{
take_chopstick[i];
take_chopstick[ (i+1) % 5] ;
EATING THE NOODLE
put_chopstick[i] );
put_chopstick[ (i+1) % 5] ;
THINKING
}
}
18
Producer – Consumer,
The Producer-Consumer problem is a classical multi-process synchronization problem, that is we are trying to achieve
synchronization between more than one process.
There is one Producer in the producer-consumer problem, Producer is producing some items, whereas there is one
Consumer that is consuming the items produced by the Producer. The same memory buffer is shared by both producers
and consumers which is of fixed-size.
The task of the Producer is to produce the item, put it into the memory buffer, and again start producing items. Whereas
the task of the Consumer is to consume the item from the memory buffer.
Problems occur in Producer-Consumer:
The producer should produce data only when the buffer is not full. In case it is found that the buffer is full, the
producer is not allowed to store any data into the memory buffer.
Data can only be consumed by the consumer if and only if the memory buffer is not empty. In case it is found
that the buffer is empty, the consumer is not allowed to use any data from the memory buffer.
Accessing memory buffer should not be allowed to producer and consumer at the same time.
do
{
//produce an item
wait(empty);
wait(mutex);
//place in buffer
signal(mutex);
signal(full);
}while(true)
do{
wait(full);
wait(mutex);
signal(mutex);
signal(empty);
}while(true)
Conclusion:
Thus, I have studied solution to classical process synchronization problems.
19
EXPERIMENT NO: 05
Write a Program to simulate page Replacement algorithm. a) FIFO b) LRU c) optimal.
1. Title:
Objectives:
- To understand memory management Concepts
- To implement page replacement technique
2. Problem Statement:
Write a program to implement page replacement technique. a) FIFO b) LRU c) OPTIMAL
3. Outcomes:
After completion of this assignment students will be able to:
- Understand the concept of memory management
-
4. Software Requirements:
Linux OS
5. Hardware Requirement:
- 4GB RAM, 500GBHDD
6. Theory Concepts:
Page replacement algorithms are an important part of virtual memory management and it helps the OS to
decide which memory page can be moved out making space for the currently needed page. However, the
ultimate objective of all page replacement algorithms is to reduce the number of page faults.
FIFO-This is the simplest page replacement algorithm. In this algorithm, the operating system keeps track of
all pages in the memory in a queue, the oldest page is in the front of the queue. When a page needs to be
replaced page in the front of the queue is selected for removal.
LRU-In this algorithm page will be replaced which is least recently used
OPTIMAL- In this algorithm, pages are replaced which would not be used for the longest duration of time in
the future. This algorithm will give us less page fault when compared to other page replacement algorithms.
20
ALGORITHM:
1. Start the process
2. Read number of pages n
3. Read number of pages no
4. Read page numbers into an array a[i]
5. Initialize avail[i]=0 .to check page hit
6. Replace the page with circular queue, while re-placing check page availability in the frame Place
avail[i]=1 if page is placed in the frame Count page faults
7. Print the
results. 8.stop
Conclusion:
Thus, I have studied Page replacement technique.
21
References:
R1. Operating Systems: Internals and Design Principles. William Stallings.
R2. Operating System: A Design-oriented Approach. Charles Patrick Crowley
22
EXPERIMENT NO: 06
1. Title:
Write a program to simulate file allocation strategy
a)Sequential
b) Indexed
c) Linked
2. Objectives:
Write a program to simulate file allocation strategy
3. Problem Statement:
Write a program to simulate file allocation strategy
a)Sequential
b) Indexed
c) Linked
4. Outcomes:
After completion of this assignment students will be able to:
- Understand the concept file allocation strategy
- Understand the lexical analysis part
- It can be used for data mining concepts.
5. Software Requirements:
Linux
6. Hardware Requirement:
-
-
-
- M/C Lenovo Think center M700 Ci3,6100,6th Gen. H81, 4GB RAM ,500GBHDD
7. Theory Concepts:
a) Sequential file allocation strategy: In this type of strategy, the files are allocated in a sequential manner
such that there is continuity among the various parts or fragments of the file.
b) Indexed file allocation strategy: In this type of strategy, the files are allocated based on the indexes that are
created for each fragment of the file such that each and every similar indexed file is maintained by the primary
a) Sequential file allocation strategy: In this type of strategy, the files are allocated in a sequential manner
such that there is continuity among the various parts or fragments of the file.
23
c) Linked file allocation strategy: In this type of strategy, the files are allocated in a linked list format where each
and every fragment is linked to the other file through either addresses or pointers. Thus, the starting location of the
file servers for the purpose of extraction of the entire file because every fragment is linked to each other)Linked file
allocation strategy: In this type of strategy, the files are allocated in a linked list format where each and every
fragment is linked to the other file through either addresses or pointers. Thus, the starting location of the file serves
for the purpose of extraction of the entire file because every fragment is linked to each other.
8. Conclusion:
Thus, we have studied file allocation strategies
References:
R1. Operating Systems: Internals and Design Principles. William Stallings.
R2. Operating System: A Design-oriented Approach. Charles Patrick Crowley
24
EXPERIMENT NO: 07
Write a Program to simulate disk Scheduling Algorithm. a) FCFS b) SSTF c) SCAN d) CSCAN e) LOOK.
1. Title:
Write a Program to simulate disk Scheduling Algorithm. a) FCFS b) SSTF c) SCAN d) CSCAN e) LOOK.
2. Objectives:
- To understand disk scheduling concepts
3. Problem Statement:
Write a Program to simulate disk Scheduling Algorithm. a) FCFS b) SSTF c) SCAN d) CSCAN e) LOOK.
4. Outcomes:
After completion of this assignment students will be able to:
Understand the concept disk Scheduling Algorithm. a) FCFS b) SSTF c) SCAN d) CSCAN e) LOOK.
5. Software Requirements:
Linux OS
Hardware Requirement:
- M/C Lenovo Think centre M700 Ci3,6100,6th Gen. H81, 4GB RAM ,500GBHDD
DESCRIPTION one of the responsibilities of the operating system is to use the hardware
efficiently. For the disk drives, meeting this responsibility entails having fast access time and large
disk bandwidth. Both the access time and the bandwidth can be improved by managing the order in
which disk I/O requests are serviced which is called as disk scheduling. The simplest form of disk
scheduling is, of course, the first-come, first-served (FCFS) algorithm. This algorithm is intrinsically
fair, but it generally does not provide the fastest service. In the SCAN algorithm, the disk arm starts
at one end, and moves towards the other end, servicing requests as it reaches each cylinder, until it
gets to the other end of the disk. At the other end, the direction of head movement is reversed, and
servicing continues. The head continuously scans back and forth across the disk. C-SCAN is a
variant of SCAN designed to provide a more uniform wait time. Like SCAN, C-SCAN moves the
head from one end of the disk to the other, servicing requests along the way. When the head reaches
the other end, however, it immediately returns to the beginning of the disk without servicing any
25
There is some important point in Disk scheduling:-
Seek Time: Seek time is the time taken to locate the disk head to a specified track where the data is to
be read or write. So the disk scheduling algorithm that gives minimum average seek time is better.
Rotational Latency: Rotational Latency is the time taken by the desired sector of disk to rotate into a
position so that it can access the read/write heads. So the disk scheduling algorithm that gives minimum
rotational latency is better.
Transfer Time: Transfer time is the time to transfer the data. It depends on the rotating speed of the
disk and number of bytes to be transferred.
Disk Access Time: Disk Access Time is=( Seek+ Rotational+ transfer time)
6. Conclusion:
Thus, I have studied disk Scheduling Algorithm. a) FCFS b) SSTF c) SCAN d) CSCAN e)
LOOK.
References:
R1. Operating Systems: Internals and Design Principles. William Stallings.
R2. Operating System: A Design-oriented Approach. Charles Patrick Crowley
26
EXPERIMENT NO: 08
To Implement UNIX System call, CP and CAT.
1. Title:
To Implement UNIX System call, CP and CAT.
.
2. Objectives:
- To understand UNIX System call, CP and CAT
-
3. Problem Statement:
Write a program to Implement UNIX System call, CP and CAT.
4. Outcomes:
After completion of this assignment students will be able to:
- Understand the concept UNIX System call, CP and CAT
5. Software Requirements:
LinuxOS
6. Hardware Requirement:
7. Theory Concepts:
cp stands for copy. This command is used to copy files or group of files or directory. It creates an exact
image of a file on a disk with different file name. cp command require at least two filenames in its arguments.
First and second syntax is used to copy Source file to Destination file or Directory.
Third syntax is used to copy multiple Sources(files) to Directory.
p command works on three principal modes of operation and these operations depend upon number and type
of arguments passed in cp command :
27
1. Two file names : If the command contains two file names, then it copy the contents of 1st file to the 2nd
file. If the 2nd file doesn’t exist, then first it creates one and content is copied to it. But if it existed then
it is simply overwritten without any warning. So be careful when you choose destination file name.
2. cp Src_file Dest_file
Suppose there is a directory named geeksforgeeks having a text file a.txt.
Example:
$ ls
a.txt
$ cp a.txt b.txt
$ ls
a.txt b.txt
3. One or more arguments : If the command has one or more arguments, specifying file names and
following those arguments, an argument specifying directory name then this command copies each source
file to the destination directory with the same name, created if not existed but if already existed then it
will be overwritten, so be careful !!.
4. cp Src_file1 Src_file2 Src_file3 Dest_directory
Suppose there is a directory named geeksforgeeks having a text file a.txt, b.txt and a directory name new in
which we are going to copy all files.
Example:
$ ls
a.txt b.txt new
$ ls new
a.txt b.txt
at(concatenate) command is very frequently used in Linux. It reads data from the file and gives their content as
output. It helps us to create, view, concatenate files. So let us see some frequently used cat commands.
1) To view a single
file Command:
$cat filename
Output
28
2) To view multiple
files Command:
$cat file1
file2 Output
Conclusion:
Thus we have studied UNIX System call, CP and CAT
References:
R1. Operating Systems: Internals and Design Principles. William Stallings.
R2. Operating System: A Design-oriented Approach. Charles Patrick Crowley
29
EXPERIMENT NO: 09
To Study and Implementation of Advance commands and filters of Linux.
8. Title:
To study and implementation of Advance Commands and filters of Linux.
9. Objectives:
- To understand commands and filters of Linux.
-
10. Problem Statement:
Implement commands and filters of Linux.
11. Outcomes:
After completion of this assignment students will be able to:
- Understand the concept of commands and filters of Linux.
In site.txt file, we are having some names. But it is in one single row and separated by space.
The fmt command is useful to display in single line multiple words into individual records separated by
space.
2. More
The more command is useful for file analysis. It will read the big size file. It will display the large file data
in page format. The page down and page up key will not work. To display the new record, we need to press
“enter” key.
cat /var/log/messages | more
We are reading the large file “/var/log/messages” of Linux via more command.
3. Less
34
The less command is like more command but it is faster with large files. It will display the large file data in
page format. The page down and page up key will work. To display the new record, we need to press
“enter” key.
We are reading the large file “/var/log/messages” of Linux via less command.
4. Head
As the name suggested, we are able to filter / read the initial or top lines or row of data. By default, it
will read the first 10 lines or records of the give data. If we need to read the more lines, then we need to specify
the number of lines that we need to read with the help of “-n” keyword.
head -n 7 file.txt
Conclusion:
Thus we have studied Advance commands and filters of Linux.
34