Operating System Laboratory - Lab Manual
Operating System Laboratory - Lab Manual
Assignment No : 1
Problem Statement :
a. Shell commands:
info - how to browse info pages, man - how to browse man pages, ls, cp, paste, diff,
cat, find, ps, chown, chmod, echo, bc, head, tail, I/O Redirection, wc, cut, pr, sort, uniq,
tee, use of Wildcard Characters, File Access Permissions (FAP)
b. Use of pipes & filters – grep and sed commands
Objectives:
Applications :
1. To enable the user to communicate with the kernel through the command interpreter.
FAQS
1. What is a pipe?
2. What is a filter?
References :
Assignment No : 2
Problem Statement :
a. Write a shell script to find single digit sum of four digit number entered
through keyboard (ex. 1234 -> 1+2+3+4 = 10)
b. Write an AWK program which will accept employee as database file containing
empNo, empName, age, designation, basicSal, HRA is 15% of basicSal, DA is 35% of
basicSal, grossSal is basicSal + DA + HRA. Database should contain at least 10
records.
Print those records where grossSal < 15000.
Objectives :
Algorithm :
Shell Program:
1. Accept any four digit number from the user.
2. Raise error if the number is not of four digit number.
3. Find the sum of digits.
4. Display the Result on the Screen.
5. Stop.
awk Program:
1. Create a file which contains the following information of employees empId,
empName, designation, basicSal with at least 10 rows.
2. Calculate the DA, and HRA of the employee by performing operation on the
column of basicSal and add them as column 5 and column 6 in the same file.
3. Calculate the grossSal and add it in the same file as column 7.
4. Print those records where grossSal < 15000.
5. Stop.
Applications :
FAQS :
1. What are different control structures used in shell programming?
2. What do you mean by positional parameters & enlist them?
3. What do you mean by shell?
4. For what purpose is AWK programming used?
5. Why is AWK more useful compared to shell programming when dealing with
database files?
6. What do you mean by $1, $2,$3..etc in AWK programming?
7. What are the different built in variables?
References :
• UNIX by Sumitabha Das
Publisher - Tata McGraw Hill
• Manual Pages in Linux System
Assignment No : 3
Problem Statement :
Implement following Algorithms:
1. Priority (Non Preemptive)
2. SJF (Preemptive)
3. RR
Objective :
1. To understand how processes are actually scheduled in the system.
2. To understand different scheduling criteria like waiting time and turn around
time on which the scheduling algorithm is selected.
Algorithm :
Round Robin :
Input :
1. Number of Processes in the System.
2. Burst time of each process.
3. Arrival time for each process.
4. Time Quantum (for Round-Robin Algorithm).
5. Priority of each process (for Priority Algorithm).
Output :
For each algorithm output should be in the form of:
1. Gantt chart showing execution of processes.
2. A table showing Waiting time and Turn-Around Time of each process.
3. Average Waiting time and Average Turn-Around Time.
Applications :
Operating system use scheduling algorithms in order to provide good response to users.
FAQS :
1. Why is scheduling used?
2. What is the difference between preemptive & non- preemptive scheduling?
3. Which algorithm is more useful & why?
4. What do you mean by time quantum?
References :
• Operating System Principles by Silberschatz, Galvin, Gagne
Publisher - Wiley Publication
• Operating Systems by William Stalling
Publisher - Prentice Hall India
Assignment No : 4
Objective :
To develop a generalized solution which accepts n processes and m resource types
with multiple instances of each resource type. The solution should be able to determine the
safety of the system after granting the request, and should be able to deny the request if
system is moving to unsafe state.
Algorithm :
Resource-Request Algorithm
Requesti = request vector for process Pi. If Requesti [j] = k then process Pi wants k instances
of resource type Rj.
1. If Requesti ≤ Needi go to step 2. Otherwise, raise error condition, since process has
exceeded its maximum claim.
2. If Requesti ≤ Available, go to step 3. Otherwise Pi must wait, since resources are
not available.
3. Pretend to allocate requested resources to Pi by modifying the state as follows:
Available = Available – Requesti;
Allocationi = Allocationi + Requesti;
Needi = Needi – Requesti;
4. Call Safety Algorithm
• If safe ⇒ the resources are allocated to Pi.
• If unsafe ⇒ Pi must wait, and the old resource-allocation state is
restored
Safety Algorithm
Input :
1. Number of Process competing for the resources.
2. Number of instances of each Resource type available (Available
Vector).
3. Number of instances of each Resource type allocated to processes
(Allocation Matrix)
4. Maximum number of instances of each Resource type required by each
process (Max Matrix).
Output :
A Menu-Driven Output with following menu:
1. Display Current Allocation Matrix.
2. Check the state of the system.
3. Make a Request.
4. Exit.
Applications :
Can be used in a system where prior information regarding usage of resources for
different processes is known in advance.
FAQS :
References :
• Operating System Principles by Silberschatz, Galvin, Gagne
Publisher - Wiley Publication
• Operating Systems by William Stalling
Publisher - Prentice Hall India
Assignment No: 5
Scope :
Objectives :
Algorithm :
PART A]
PseudoCode For Readers :
var wrt, mutex: semaphore;
readcount: integer;
begin
readcount := 0;
wrt := 1;
mutex := 1;
parbegin
repeat (* reader process *)
(* do something *)
wait(mutex);
readcount := readcount + 1;
if readcount = 1 then
wait(wrt);
signal(mutex);
(* read the Shared Data *)
wait(mutex);
readcount := readcount - 1;
if readcount = 0 then
signal(wrt);
signal(mutex);
(* do something else *)
until false;
end
PART B]
Pseudo code For Writers:
repeat (* writer process *)
(* do something *)
wait(wrt);
(* write to the Shared data *)
signal(wrt);
(* do something else *)
until false;
parend;
end.
Input :
Output :
Applications :
FAQS :
References :
Assignment No : 6
Scope :
1. Create 5 threads for representing 5 philosophers
2. Make use of semaphore variables to represent the chopsticks.
3. Implement the algorithm which may lead to deadlock as well as the algorithm
which overcome this drawback by implementing asymmetric solution.
Objectives :
Output :
Message depicting whether particular Philosopher is Thinking or Eating.
Algorithm :
This algorithm which may lead to deadlock wherein chopstick is array of semaphore
and i being philosopher thread under execution.
While (true)
{
// think
wait ( chopstick[i] );
wait ( chopstick[ (i + 1) % 5] );
// eat
signal ( chopstick[i] );
signal (chopstick[ (i + 1) % 5] );
}
Applications :
FAQS :
References :
• Operating System Principles by Silberschatz, Galvin, Gagne
Publisher - Wiley Publication
• Beginning Linux Programming by Neil Mattew and Richard Stones
Publisher - Wrox Publication
Assignment No : 7
Scope :
To implement following Algorithms:
1. LRU
2. OPTIMAL
3. MFU
Objective :
1. To understand the concept of demand paging.
2. To understand how pages are selected for replacement.
Algorithm :
Optimal:
1. Start.
Input :
1. Number of Page Frames in memory in case of MFU and OPTIMAL or Size of
Stack in case of LRU.
2. Reference String (Page referred by process during execution).
Output :
1. Graphical output showing allocation of frames to pages in case of MFU and
OPTIMAL and Stack position with every reference in case of LRU.
2. Number of page faults occurred.
Applications :
References :
• Operating System Principles by Silberschatz, Galvin, Gagne
Publisher - Wiley Publication
• Operating Systems by William Stalling
Publisher - Prentice Hall India
Assignment No : 8
Scope :
Objectives :
Algorithm :
1. Start.
2. Accept the number of tracks n.
3. Accept the requested tracks and store it in the track [ ].
4. Consider the first value of track[ ] as starting track .
5. Process the track values in given order to calculate difference as trackdiff [i]
= track[i] - track[i+1] .
6. Calculate totaldiff = totaldiff + trackdiff[i].
7. Calculate average seek time.
8. Display the value of average seek time.
9. Stop.
1. Start.
2. Accept the number of tracks n.
3. Accept the requested tracks and store it in track[ ].
4. Consider the first value of track[ ] as starting track .
5. First process all the tracks which are having value less than starting track in
decreasing order of tracks as trackdiff[i] = track[i]-track[i+1] .
6. Then process all the tracks which are having value greater than starting in
increasing order of track as trackdiff[i] = track[i] - track[i+1].
7. Calculate totaldiff = totaldiff + trackdiff[i]
8. Calculate average seek time.
9. Display the value of average seek time.
10. Stop.
C-SCAN:
1. Start.
2. Accept the number of tracks n.
3. Accept the requested tracks and store it in track[ ]
4. Consider the first value of track[ ] as starting track .
5. First process all the tracks which are having value greater than starting track in
increasing order of track as trackdiff[i]= track[i] - track[i+1]
6. Then process all the tracks which are having value less than starting track in
increasing order of track(Wrap around to starting track) as trackdiff[i] = track[i] -
track[i+1]
7. Calculate totaldiff = totaldiff + trackdiff[i]
8. Calculate average seek time.
9. Display the value of average seek time.
10. Stop
Input :
1. Number of cylinders in the disks
2. Sequence of disk requests
Output :
1. Graphical output showing how the requests were satisfied.
2. Average seek-time.
Applications :
1. Applicable in Multimedia application to reduce disk access.
FAQS :
1. What do you mean by seek time?
2. What is difference between SCAN & C-SCAN method?
3. Give an analysis of comparison of 4 algorithms.
References :
• Operating System Principles by Silberschatz, Galvin, Gagne
Publisher - Wiley Publication
• Operating Systems by William Stalling
Publisher - Prentice Hall India
Assignment No : 9
Title : A program to implement inter process communication using pipe system call.
Objective :
1. To demonstrate the IPC between two different processes.
2. To understand how to make use of fork ( ) system call to create the new process.
3. To understand how to make use of pipe ( ) system call as a medium of IPC
between parent and child processes.
Algorithm :
1. Create the child process using fork( ) system call
2. Accept the input data in parent process.
3. Create the pipe as a medium of IPC using pipe ( ) system call.
4. Parent process should send the accepted data through write end of created
pipe to child process.
5. Child process should receive the sent item through read end of pipe &
perform necessary operations on it & print the result.
Input :
Data requested by parent process.
Output :
Data manipulated by child process
References :
• Beginning Linux Programming by Neil Mattew and Richard Stones
Publisher - Wrox Publication
• Manual Pages in Linux System