Os Manual
Os Manual
OPERATING SYSTEMS
Lab Manual (CSE18R273)
Section : ………………………………………………………..
1
TABLE OF CONTENTS
1 Bonafide Certificate 3
3 Course Plan 5
4 Introduction 11
Experiments
2
DEPARTMENT OF INFORMATION TECHNOLOGY
BONAFIDE CERTIFICATE
REGISTER NUMBER
Marks Faculty
S.No Date Experiment
(100) Signature
10
4
DEPARTMENT OF INFORMATION TECHNOLOGY
Pre-requisite:
CSE18R174 /Computer Architecture and Organization
Course Description:
This course introduces the fundamentals concepts of Operating Systems. Details about Computer
System Organization and Computer System Architecture, Operating System Structure and Services are
covered. Operating System Design and Implementation, Process Concept, Process Scheduling, Inter-
process Communication are covered. This course also covers Threads, Multithreading, CPU Scheduling,
Scheduling Algorithms, Critical section Problem, Semaphores.
This course also introduces deadlocks, Deadlock prevention, deadlock avoidance, deadlock
detection and recovery from deadlocks. Paging, segmentation, virtual memory demand paging and page
replacement are also covered. This course also introduces file concept, file system and directory
implementation, Mass Storage structure, Disk Scheduling, RAID structure, I/O Hardware, Protection and
Security.
5
PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)
PEO 1 The graduates are trained to gain employment as an IT professional and to pursue higher
studies to cater the global needs.
PEO 2 The graduates could comprehend, analyze, design and create novel products and
technologies that provide solution to real world problems.
PEO3 PEO 3 The graduates acquire multidisciplinary knowledge with ethical standards, effective
communication skills and management skills to work as part of teams on all diverse
professional environments.
PROGRAM OUTCOMES (POs)
PO 01 Ability to apply knowledge of mathematics, science and computer engineering to solve
computational problems
PO 03 Capability to design and develop computing systems to meet the requirement of industry
And society with due consideration for public health, safety and environment.
PO 04 Ability to apply knowledge of design of experiment and data analysis to derive solutions
In complex computing problems.
PO 05 Ability to develop and apply modeling, simulation and prediction tools and techniques to
engineering problems.
PO 06 Assess and understand the professional, legal, security and societal responsibilities
PO 12 Understanding the need for technological changes and engage in life-long learning.
6
ABET STUDENT OUTCOMES(ASO)
ASO1 Analyze a complex computing problem and to apply principles of computing and other relevant
disciplines to identify solutions
ASO2 Design, implement, and evaluate a computing-based solution to meet a given set of computing
requirements in the context of the program’s discipline
ASO3 Communicate effectively in a variety of professional contexts
ASO4 Recognize professional responsibilities and make informed judgments in computing practice
based on legal and ethical principles
ASO5 Function effectively as a member or leader of a team engaged in activities appropriate to the
program’s discipline
ASO6 Identify and analyze user needs to take them into account in the selection, creation, integration,
evaluation, and administration of computing-based systems
POs
1 2 3 4 5 6 7 8 1. 9 10 11 12
CO1 H M L
CO2 M M H L
CO3 M M H L
CO4 M M H L
CO5 M M H L
7
LIST OF EXPERIMENTS:
Experi Cumulati
No. of
ment Name of the Experiment ve No. of
periods
No. periods
8
New Additional Experiments:
1. Implementation of Real time scheduling algorithm in Industrial embedded application .(CO5)
2. Implementation of Private Shared Anonymous Paging algorithm for interactive real time application . (CO5)
Assessment Method:
S.no Assessment Split up
9
Mark Distribution for Regular Experiments:
Efficiency of
Algorithm Efficiency VIVA
S.No Experiments of program Output VOICE
10
INTRODUCTION
This lab complements the operating systems course. Students will gain practical experience with
designing and implementing concepts of operating systems such as system calls, CPU scheduling,
process management, memory management, file systems and deadlock handling and disk
scheduling using C language in Linux environment.
OUTCOMES:
Upon the completion of Operating Systems practical course, the student will be able to:
1. Understand and implement basic services and functionalities of the operating system using
system calls.
2. Use modern operating system calls and synchronization libraries in software/ hardware
interfaces.
3. Understand the benefits of thread over process and implement synchronized programs using
multithreading concepts.
4. Analyze and simulate CPU Scheduling Algorithms like FCFS, Round Robin, SJF, and Priority.
5. Implement memory management schemes and page replacement schemes.
6. Simulate file allocation and organization techniques.
7. Understand the concepts of deadlock in operating systems and implement them in
multiprogramming system.
11
BASIC LINUX COMMANDS
AIM:
To study the UNIX commands for accessing files and directories.
COMMANDS DESCRIPTION:
12
EXECUTION & OUTPUT:
13
14
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Result:
15
Ex. No. 1b General Purpose Utility Commands
AIM:
To work with some of the general purpose utility commands in UNIX.
COMMANDS DESCRIPTION:
16
rev - reverse lines of a file or files
EXECUTION & OUTPUT:
17
18
Sample Viva-Voce questions:
1. What is UNIX?
2. How is Unix differ from Linux
3. What is operating system?
4. What are the various components of a computer system?
5. What are the different operating systems?
6. Write a command to create a directory.
7. What command can you use to display the first 3 lines of text from a file and how does it
work?
8. How do you reverse the string?
9. How can you find out what a command does?
10. Write a script that prints out date information in this order: time, day of week, day number,
month, year.
11. Is there a way to erase all files in the current directory, including all its sub-directories,
using only one command?
Algorithm
Program
Output
Viva
Result
19
SYSTEM CALLS
Ex. No. 2a Fork System Call
INSTRUCTIONS:
System call fork() is used to create processes. It takes no arguments and returns a process ID. The
purpose of fork() is to create a new process, which becomes the child process of the caller. After a
new child process is created, both processes will execute the next instruction following
the fork() system call. Therefore, we have to distinguish the parent from the child. This can be
done by testing the returned value of fork():
If fork() returns a negative value, the creation of a child process was unsuccessful.
fork() returns a zero to the newly created child process.
fork() returns a positive value, the process ID of the child process, to the parent. The
returned process ID is of type pid_t defined in sys/types.h. Normally, the process ID is an
integer. Moreover, a process can use function getpid() to retrieve the process ID assigned to
this process.
Exercise:
If p1 and p2 are two process and p2 is a child of p1. Write a program to implement how the child
will fork for a system call.
AIM:
To write a program to create a child process using the system calls –fork.
ALGORITHM:
20
.
PROGRAM:
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
21
Result
DESCRIPTION:
EXEC is a functionality of an operating system that runs an executable file in the context of
an already existing process, replacing the previous executable. This act is also referred to as
an overlay. It is especially important in Unix-like systems, although exists elsewhere. As a new
process is not created, the process identifier (PID) does not change, but the machine code, data, heap,
and stack of the process are replaced by those of the new program.
Exercise
When a child fork for a parent process, write a program how to use exec system calls.
AIM:
To write a program to display time and date using exec system call.
ALGORITHM:
22
PROGRAM:
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
23
Result:
DESCRIPTION:
stat() is a Unix system call that returns file attributes about an inode. The semantics
of stat() vary between operating systems. As an example, Unix command ls uses this system call to
retrieve information on files that includes:
AIM:
ALGORITHM:
PROGRAM:
24
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
Result:
25
Ex. No. 2d Wait System Call
DESCRIPTION:
The system call wait() is blocks the calling process until one of its child processes exits or
a signal is received. For our purpose, we shall ignore signals. wait() takes the address of an integer
variable and returns the process ID of the completed process. Some flags that indicate the
completion status of the child process are passed back with the integer pointer. One of the main
purposes of wait() is to wait for completion of child processes.
1. If there are at least one child processes running when the call to wait() is made, the caller
will be blocked until one of its child processes exits. At that moment, the caller resumes its
execution.
2. If there is no child process running when the call to wait() is made, then this wait() has no
effect at all. That is, it is as if no wait() is there.
AIM:
To write a program using wait system call.
ALGORITHM:
PROGRAM:
26
27
Sample Viva-Voce questions:
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Result
Total
28
Ex. No. 2e Input Output system Call
DESCRIPTION:
- creat(name, permissions) – Used to create a file with the name and mode specified. Here,
permission would be a number. 0666 means read write permissions.
- open(name, mode) – Used to open a file name in the mode (read or write) specified. 0 is for
opening in read mode, 1 for writing and 2 for both.
- lseek(fd, offest, whence) - Move the read/write pointer to the specified location.
AIM:
To write a program to implement the concept of I/O call.
ALGORITHM:
29
PROGRAM:
30
Sample Viva-Voce questions:
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
Result
31
SCHEDULING ALGORITHMS
AIM:
To write a program using C in UNIX environment to implement the first come first serve
scheduling.
ALGORITHM:
EXAMPLE:
Suppose there are 3 processes in the ready list. Further assume that they had entered into
the ready list in the order P0, P1, P2.
i T(Pi)
0 24
1 3
2 3
32
Gantt (Gantl Chart):-
P0 P1 P2
0 24 27 30
Turn Around Time:-
TRND(P0)=T(P0)=24
TRND(P1)=T(P1)+ TRND(P0)
=3+24=27
TRND(P2)=T(P2)+ TRND(P1)
=3+27=30
Waiting Time:-
W(P0)=0
W(P1)= TRND(P0)=24 or W(P1)= W(P0)+burst time of P0 = 0+24=24
W(P2)= TRND(P1)=27
a. What is the average turnaround time for these processes with the FCFS scheduling algorithm?
33
b. What is the average turnaround time for these processes with the SJF scheduling algorithm?
c. What is the average turn around time for these processes with the round robin scheduling
algorithm?
d. What is the average turn around time for these processes with the priority scheduling algorithm?
e. The SJF algorithm is supposed to improve performance, but notice that we chose to run process
P1 at time 0 because we did not know that two shorter processes would arrive soon. Compute what
the average turnaround time will be if the CPU is left idle for the first 1 unit and then SJF
scheduling is used. Remember that processes P1 and P2 are waiting during this idle time, so their
waiting time may increase. This algorithm could be called future-knowledge scheduling.
PROGRAM:
34
35
Assessment of an Individual
experiment
Algorithm
Program
Output
Viva
Total
Result:
36
Ex. No. 3b Shortest Job First Scheduling
AIM:
To write a program using C in UNIX environment to implement the shortest job next
concept.
ALGORITHM:
EXAMPLE:
In the following example assume no other jobs arrive during the servicing of all jobs in the
ready list. Assume there are 4 jobs.
i T(Pi)
0 5
1 10
2 8
3 3
Since the service time of P3 is 3, which is the shortest, P3 is scheduled first and then P0 is
scheduled next and so on.
37
Gantt Chart:-
0 3 8 16 26
P3 P0 P2 P1
TRND(P3)= T(P3)= 3
W(P1)=16
W(P2)= 8
W(P3)= 0
PROGRAM:
38
39
40
Assessment
of an Individual
experiment
Algorithm
Program
Output
Viva
Total
Result
41
Ex. No. 3c Round Robin Scheduling
AIM:
To write a program using C in UNIX environment to implement Round-robin scheduling
concept.
ALGORITHM:
EXAMPLE:
Suppose the ready list contains the processes as shown in table and time quantum is 4 with
a negligible amount of time for context switching.
i T(Pi)
0 24
1 3
2 3
Gantt Chart:-
0 4 7 10 14 18 22 26 30
P0 P1 P2 P0 P0 P0 P0 P0
TRND(P0)=30
42
TRND(P1)=7
TRND(P2)=10
PROGRAM:
43
44
45
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
Result:
46
Ex.No. 3d Priority Scheduling
AIM:
To implement the priority scheduling using C in UNIX environment.
ALGORITHM:
EXAMPLE:
Suppose the ready list contains the processes as shown in table.
i T(Pi) Priority
0 24 2
1 3 1
2 3 3
Gantt Chart:-
0 3 27 30
P1 P0 P2
47
Turn Around Time:-
TRND(P0)=27
TRND(P1)=3
TRND(P2)=30
Average Turn Around Time:-
TRND =(30+3+27)/3=20
Waiting Time:-
W(P0)=3
W(P1)=0
W(P2)=27
Average Waiting Time:-
W=(3+0+27)/3=10
PROGRAM:
48
49
50
51
Sample Viva-Voce questions:
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
Result
52
Ex.No : 4 SIMULATATION of IPC in UNIX
AIM:
DESCRIPTION:
In the discussion of the fork() system call, we mentioned that a parent and its children have
separate address spaces. While this would provide a more secured way of executing parent and
children processes (because they will not interfere each other), they shared nothing and have no
way to communicate with each other. A shared memory is an extra piece of memory that is
attached to some address spaces for their owners to use. As a result, all of these processes share
the same memory segment and have access to it. Consequently, race conditions may occur if
memory accesses are not handled properly. The following figure shows two processes and their
address spaces. The yellow rectangle is a shared memory attached to both address spaces and both
process 1 and process 2 can have access to this shared memory as if the shared memory is part of
its own address space. In some sense, the original address spaces is "extended" by attaching this
shared memory.
Shared memory is a feature supported by UNIX System V, including Linux, SunOS and Solaris.
One process must explicitly ask for an area, using a key, to be shared by other processes. This
process will be called the server. All other processes, the clients, that know the shared area can
access it. However, there is no protection to a shared memory and any process that knows it can
53
access it freely. To protect a shared memory from being accessed at the same time by several
processes, a synchronization protocol must be setup.
A shared memory segment is identified by a unique integer, the shared memory ID. The shared
memory itself is described by a structure of type shmid_ds in header file sys/shm.h. To use this
file, files sys/types.h and sys/ipc.h must be included.
ALGORITHM:
PROGRAM:
54
55
56
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
Result
57
Ex.No: 5 IMPLEMENTATION OF DEADLOCK - BANKERS ALGORITHM
AIM:
To write a UNIX C Program for the Implementation of Banker's
PROBLEM DESCRIPTION:
The Banker’s Algorithm was designed and developed by a Dutch Computer Scientist,
Edsger Djikstra. The Banker’s Algorithm is a Resource Allocation and a Deadlock Avoidance
Algorithm.
This algorithm takes analogy of an actual bank where clients request to withdraw cash. The
Banking Authorities have some data according to which the cash is lent to the client. The Banker
cannot give more cash than the client’s request and the total cash available in the bank.
1. Safety Test Algorithm: This algorithm checks the current state of the system to maintain its
Safe State.
58
2. Resource Request Handling Algorithm: This algorithm verifies if the requested resources,
after their allocation to the processes affects the Safe State of the System. If it does, then the
request of the process for the resource is denied, thereby maintaining the Safe State.
A State is considered to be Safe if it is possible for all the Processes to Complete its Execution
without causing any Deadlocks. An Unsafe State is the one in which the Processes cannot
complete its execution.
Exercise:
ALGORITHM:
59
PROGRAM:
60
61
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
Result
62
Ex. No.:6 PAGE REPLACEMENT ALGORITHMS
AIM:
To write a program in C to implement page replacement algorithm FIFO
PROBLEM DESCRIPTION:
Page replacement algorithms are used to decide what pages to page out when a page needs
to be allocated. This happens when a page fault occurs and free page cannot be used to satisfy
allocation
LRU:
“Replace the page that had not been used for a longer sequence of time”. The frames are
empty in the beginning and initially no page fault occurs so it is set to zero. When a page fault
occurs the page reference sting is brought into the memory. The operating system keeps track of all
pages in the memory, thereby keeping track of the page that had not been used for longer sequence
of time. If the page in the page reference string is not in memory, the page fault is incremented and
the page that had not been used for a longer sequence of time is replaced. If the page in the page
reference string is in the memory take the next page without calculating the next page. Take the
next page in the page reference string and check if the page is already present in the memory or
not. Repeat the process until all pages are referred and calculate the page fault for all those pages
in the page references string for the number of available frames.
Exercise
63
• Optimal replacement
Algorithm
Program
64
65
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
Result
66
MEMORY MANAGEMENT FUNCTIONS
Exercise:
Given memory partition of 100 KB, 500 KB, 200 KB, 300 KB and 600 KB (in order), how would
each of the first-fit, best fit and worst fit algorithms place processes of 212 KB, 417 KB, 112 KB
and 426 KB (in order)? Which algorithm makes the most efficient use of memory? Either it is best
fit.
ALGORITHM:
PROGRAM:
67
68
69
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
Result
70
Ex. No. 7b Memory Management Scheme using First Fit.
AIM:
To write a C program to implement the memory management scheme using first fit
Exercise:
Given memory partition of 100 KB, 500 KB, 200 KB, 300 KB and 600 KB (in order), how would
each of the first-fit, best fit and worst fit algorithms place processes of 212 KB, 417 KB, 112 KB
and 426 KB (in order)? Which algorithm makes the most efficient use of memory? Either it is first
fit.
ALGORITHM:
PROGRAM:
71
72
73
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
Result
74
Ex. No. 7c Memory Management Scheme using Worst Fit.
AIM:
To write a C program to implement the memory management scheme using worst fit.
Exercise:
Given memory partition of 100 KB, 500 KB, 200 KB, 300 KB and 600 KB (in order), how would
each of the first-fit, best fit and worst fit algorithms place processes of 212 KB, 417 KB, 112 KB
and 426 KB (in order)? Which algorithm makes the most efficient use of memory? Either it is
worst fit.
ALGORITHM:
PROGRAM:
75
76
77
Sample Viva-Voce questions:
1. What is a process?
2. Differentiate between first fit, best fit and worst fit.
3. How does swapping result in better memory management?
4. What is first fit?
5. What is the amount of memory required for storing the page tables of the process if a
process has only following pages in its virtual address space?
Assessment of an
Individual
experiment
Algorithm
Program
Output
Viva
Total
Result
78
Ex No: 8 IMPLEMENTATION OF DISK SCHEDULING ALGORITHMS
AIM:
To write a ‘C’ program to implement the Disk Scheduling algorithm for First Come First
Served (FCFS), Shortest Seek Time First (SSTF), and SCAN.
PROBLEM DESCRIPTION:
Disk Scheduling is the process of deciding which of the cylinder request is in the ready
queue is to be accessed next.
The access time and the bandwidth can be improved by scheduling the servicing of disk
I/O requests in good order.
Access Time:
The access time has two major components: Seek time and Rotational Latency.
Seek Time:
Seek time is the time for disk arm to move the heads to the cylinder containing the
desired sector.
Rotational Latency:
Rotational latency is the additional time waiting for the disk to rotate the desired sector to
the disk head.
Bandwidth:
The disk bandwidth is the total number of bytes transferred, divided by the total time
between the first request for service and the completion of the last transfer.
PROCEDURE:
1. Input the maximum number of cylinders and work queue and its head starting position.
2. First Come First Serve Scheduling (FCFS) algorithm – The operations are performed in
order requested
7. Since seek time increases with the number of cylinders traversed by the head, SSTF chooses
the pending request closest to the current head position.
9. SCAN Scheduling algorithm –The disk arm starts at one end of the disk, and moves toward
the other end, servicing requests as it reaches each cylinder, until it gets to the other end of the
disk.
10. At the other end, the direction of head movement is reversed and servicing continues.
11. The head continuously scans back and forth across the disk.
Exercise:
Consider that a disk drive has 5,000 cylinders, numbered 0 to 4,999. The drive is currently serving
a request at cylinder 2,150, and the previous request was at cylinder 1,805. The queue of pending
requests, in FIFO order, is:
2,069, 1,212, 2,296, 2,800, 544, 1,618, 356, 1,523, 4,965, 3681
Starting from the current head position, what is the total distance (in cylinders) that the disk arm
moves to satisfy all the pending requests for each of the following disk-scheduling algorithms?
a. FCFS
b. SSTF
c. SCAN
d. LOOK
e. C-SCAN
f. C-LOOK
Program :
80
81
82
83
84
85
Viva-Voce questions:
Algorithm
Program
Output
Viva
Total
Result
86
Ex No: 9 IMPLEMENTATION ACCESS CONTROL MECHANISMS
AIM:
PROBLEM DESCRIPTION:
Access control for an operating system determines how the operating system implements
accesses to system resources by satisfying the security objectives of integrity, availability, and
secrecy. Such a mechanism authorizes subjects (e.g., processes and users) to perform certain
operations (e.g., read, write) on objects and resources of the OS (e.g., files, sockets).
Operating system is the main software between the users and the computing system
resources that manage tasks and programs. Resources may include files, sockets, CPU, memory,
disks, timers, network, etc. System administrators, developers, regular users, guests, and even
hackers could be the users of the computing system
Program :
87
88
89
90
91
Viva-Voce questions:
Algorithm
Program
Output
Viva
Total
Result
92
EX. NO: 10a IMPLEMENTATION OF CAESAR CIPHER
AIM:
To implement the simple substitution technique named Caesar cipher using C language.
ALGORITHM:
93
OUTPUT:
RESULT:
94
EX. NO: 10b IMPLEMENTATION OF PLAYFAIR CIPHER
AIM:
ALGORITHM:
95
96
97
98
OUTPUT:
RESULT:
99
EX. NO: 10c IMPLEMENTATION OF HILL CIPHER
AIM:
ALGORITHM:
100
101
OUTPUT:
RESULT:
102
EX. NO: 10d IMPLEMENTATION OF VIGENERE CIPHER
AIM:
ALGORITHM:
103
104
OUTPUT:
105
Viva-Voce questions:
Algorithm
Program
Output
Viva
Total
Result
106