Professional Documents
Culture Documents
OS Lab Manual 0704CS191002 Abhijeet Shastri
OS Lab Manual 0704CS191002 Abhijeet Shastri
DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
LAB MANUAL
Year/Sem : II/IV
OBJECTIVE:
To understand FCFS CPU scheduling algorithm.
ALGORITHM:
1. Start the process
2. Get the number of processes to be inserted
3. Get the value for burst time of each process from the user
4. Having allocated the burst time(bt) for individual processes , Start with the first process from it’s
initial position let other process to be in queue
5. Calculate the waiting time(wt) and turnaround time(tat) as
Wt(pi) = wt(pi-1) + tat(pi-1) (i.e wt of current process = wt of previous process + tat of previous
process)
tat(pi) = wt(pi) + bt(pi) (i.e tat of current process = wt of current process + bt of current process)
6. Calculate the total and average waiting time and turnaround time
7. Display the values
8. Stop the process
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.2
Unit/Topic: 3/CPU Scheduling
PROBLEM DEFINITION:
Write a program to implement SJF CPU scheduling algorithm.
OBJECTIVE:
To understand SJF CPU scheduling algorithm
ALGORITHM:
Algorithm:
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.3
Unit/Topic: 3/CPU Scheduling
PROBLEM DEFINITION:
Write a program to implement Write a program to implement Priority CPU Scheduling algorithm.
OBJECTIVE:
To understand Priority CPU Scheduling algorithm.
ALGORITHM:
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.4
Unit/Topic: 3/CPU Scheduling
PROBLEM DEFINITION:
Write a program to implement Round Robin CPU scheduling algorithm.
OBJECTIVE:
To understand Round Robin CPU scheduling algorithm.
ALGORITHM:
1. Start the process
2. Get the number of elements to be inserted
3. Get the value for burst time for individual processes
4. Get the value for time quantum
5. Make the CPU scheduler go around the ready queue allocating CPU to each process for the time
interval specified
6. Make the CPU scheduler pick the first process and set time to interrupt after quantum. And after
it's expiry dispatch the process
7. If the process has burst time less than the time quantum then the process is released by the CPU
8. If the process has burst time greater than time quantum then it is interrupted by the OS and the
process is put to the tail of ready queue and the schedule selects next process from head of the
queue
9. Calculate the total and average waiting time and turnaround time
10. Display the results
11. Stop the process
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.5
Unit/Topic: 4/IPC
PROBLEM DEFINITION:
Write a program to implement classical inter process communication problem(producer consumer).
OBJECTIVE:
To understand classical inter process communication problem (producer consumer).
ALGORITHM:
The producer-consumer problem illustrates the need for synchronization in systems where many
processes share a resource. In the problem, two processes share a fixed-size buffer. One process
produces information and puts it in the buffer, while the other process consumes information from
the buffer. These processes do not take turns accessing the buffer, they both work concurrently.
Here in lies the problem. What happens if the producer tries to put an item into a full buffer? What
happens if the consumer tries to take an item from an empty buffer?
In order to synchronize these processes, we will block the producer when the buffer is full, and we
will block the consumer when the buffer is empty. So the two processes, Producer and Consumer,
should work as follows:
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.6
Unit/Topic: 4/IPC
PROBLEM DEFINITION:
Write a program to implement classical inter process communication problem (Reader Writers).
OBJECTIVE:
To understand classical inter process communication problem (Reader Writers).
ALGORITHM:
Consider a situation where we have a file shared between many people.
• If one of the people tries editing the file, no other person should be reading or writing at the
same time, otherwise changes will not be visible to him/her.
• However if some person is reading the file, then others may read it at the same time.
Precisely in OS we call this situation as the readers-writers problem
Problem parameters:
• One set of data is shared among a number of processes
• Once a writer is ready, it performs its write. Only one writer may write at a time
• If a process is writing, no other process can read it
• If at least one reader is reading, no other process can write
• Readers may not write and only read
Solution when Reader has the Priority over Writer
Here priority means, no reader should wait if the share is currently opened for reading.
Three variables are used: mutex, wrt, readcnt to implement solution
1. semaphore mutex, wrt; // semaphore mutex is used to ensure mutual exclusion when
readcnt is updated i.e. when any reader enters or exit from the critical section and
semaphore wrt is used by both readers and writers
2. int readcnt; // readcnt tells the number of processes performing read in the critical
section, initially 0
Writer process:
1. Writer requests the entry to critical section.
2. If allowed i.e. wait() gives a true value, it enters and performs the write. If not allowed, it
keeps on waiting.
3. It exits the critical section.
do {
// writer requests for critical section
wait(wrt);
2. If allowed:
• it increments the count of number of readers inside the critical section. If this reader is
the first reader entering, it locks the wrt semaphore to restrict the entry of writers if any
reader is inside.
• It then, signals mutex as any other reader is allowed to enter while others are already
reading.
• After performing reading, it exits the critical section. When exiting, it checks if no more
reader is inside, it signals the semaphore “wrt” as now, writer can enter the critical
section.
3. If not allowed, it keeps on waiting.
do {
readcnt--;
Thus, the semaphore ‘wrt‘ is queued on both readers and writers in a manner such that preference is
given to readers if writers are also there. Thus, no reader is waiting simply because a writer has
requested to enter the critical section.
INPUT SET:
OUTPUT SET:
OBJECTIVE:
To understand classical inter process communication problem (Dining Philosophers).
ALGORITHM:
Producer consumer problem is a synchronization problem. There is a fixed size buffer where the
producer produces items and that is consumed by a consumer process. One solution to the producer-
Consumer problem uses shared memory. To allow producer and consumer processes to run
concurrently, there must be available a buffer of items that can be filled by the producer and
emptied by the consumer. This buffer will reside in a region of memory that is shared by the
producer and consumer processes. The producer and consumer must be synchronized, so that the
consumer does not try to consume an item that has not yet been produced.
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.8
Unit/Topic: 3/Virtual Memory
PROBLEM DEFINITION:
Write a program to implement various page replacement algorithm.
OBJECTIVE:
To understand various page replacement algorithm.
ALGORITHM:
FIFO
1. Start the process
4. Check the need of replacement from old page to new page in memory
LRU Algorithm
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.9
Unit/Topic: 2/Disk Scheduling
PROBLEM DEFINITION:
Write a program to implement Disk & Drum scheduling Algorithms (FCFS and SCAN) OBJECTIVE:
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.10
Unit/Topic: 4/Deadlock
PROBLEM DEFINITION:
Write a program to implement Banker’s algorithms.
OBJECTIVE:
To understand Banker’s algorithms.
ALGORITHM:
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.11
Unit/Topic: 4/Deadlock
PROBLEM DEFINITION:
Write a program to implement Remote Procedure Call (RPC).
OBJECTIVE:
To understand Remote Procedures Call (RPC).
ALGORITHM:
A remote procedure call is an inter-process communication technique that is used for client-server
based applications. It is also known as a subroutine call or a function call.
A client has a request message that the RPC translates and sends to the server. This request may be
a procedure or a function call to a remote server. When the server receives the request, it sends the
required response back to the client. The client is blocked while the server is processing the call and
only resumed execution after the server is finished.
The sequence of events in a remote procedure call is given as follows:
• The remote procedure call is a concept that can be implemented in different ways. It is not a
standard.
• There is no flexibility in RPC for hardware architecture. It is only interaction based.
• There is an increase in costs because of remote procedure call.
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.12
Unit/Topic: 4/Deadlock
PROBLEM DEFINITION:
Write a Devices Drivers for any Device or peripheral.
OBJECTIVE:
To understand Devices Drivers
ALGORITHM:
Device Drivers are the software through which, the kernel of a computer communicates with
different hardware, without having to go into the details of how the hardware works. It is a software
that controls a hardware part attached to a computer and allows the computer to use the hardware by
providing a suitable interface. This means that the operating system need not go into the details
about how the hardware part works. It also provides a common interface so that the operating
system or the Kernel can communicate with the hardware.
Thus, the purpose of device drivers is to allow smooth functioning of the hardware for which it is
created and to allow it to be used with different operating systems.
There are device drivers for almost every device associated with a computer – from BIOS to even
virtual machines and more. Device drivers can be broadly be classified into two categories:
User Mode Device Drivers are the ones usually triggered by users during their session on a
computer. It might be thought of devices that the user brought to the computer other than the kernel
devices. Drivers for most of the Plug and Play devices fall into this category. User Device Drivers
can be written to disk so that they don’t act tough on the resources. However, for the drivers related
to gaming devices, it is recommended to keep them in main memory (RAM).
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.13
Unit/Topic: 3/CPU Scheduling
PROBLEM DEFINITION:
Compare various CPU Scheduling Algorithms over different Scheduling Criteria.
OBJECTIVE:
To understand various CPU Scheduling Algorithms over different Scheduling Criteria.
ALGORITHM:
Compare FCFS, SJF, Round Robin and Priority scheduling?
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE: