Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 44

MAHAKAL INSTITUTE OF TECHNOLOGY, UJJAIN

Approved By: All India Council of Technical Education (New Delhi)

DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING

LAB MANUAL

Name of Student : Abhijeet Shastri

Name of Lab : Operating Systems

Subject Code : CS- 405

Branch : Computer Science and Engineering

Year/Sem : II/IV

Affiliated to Rajiv Gandhi Prodyogiki Vishwavidyalaya, Bhopal (MP)


INDEX
S. Name of Experiment Date Sign Remark
No.
1. Write a program to implement FCFS CPU scheduling algorithm.

2. Write a program to implement SJF CPU scheduling algorithm.

3. Write a program to implement Priority CPU Scheduling algorithm.

4. Write a program to implement Round Robin CPU scheduling algorithm.

5. Write a program to implement classical inter process communication


problem (producer-consumer).
6. Write a program to implement classical inter process communication
problem (Readers-Writers).
7. Write a program to implement classical inter process communication
problem (Dining_Philosophers).
8. Write a program to implement various page replacement algorithms.

9. Write a program to implement various Disk & Drum scheduling Algorithms

10. Write a program to implement Banker’s algorithms.

11. Write a program to implement Remote Procedure Call (RPC).

12. Write a Devices Drivers for any Device or peripheral.

13. Compare various CPU Scheduling Algorithms over different Scheduling


Criteria.
List of Experiments
Operating Systems (CS-405)

1. Write a program to implement FCFS CPU scheduling algorithm.


2. Write a program to implement SJF CPU scheduling algorithm.
3. Write a program to implement Priority CPU Scheduling algorithm.
4. Write a program to implement Round Robin CPU scheduling algorithm.
5. Write a program to implement classical inter process communication problem (producer
consumer).
6. Write a program to implement classical inter process communication problem(Reader
Writers)
7. Write a program to implement classical inter process communication problem (Dining
Philosophers).
8. Write a program to implement various page replacement algorithms.
9. Write a program to implement various Disk & Drum scheduling Algorithms
10. Write a program to implement Banker’s algorithms.
11. Write a program to implement Remote Procedure Call (RPC).
12. Write a Devices Drivers for any Device or peripheral.
13. Compare various CPU Scheduling Algorithms over different Scheduling Criteria.
EXPERIMENT NO.1
Unit/Topic: 3/CPU Scheduling
PROBLEM DEFINITION:
Write a program to implement FCFS CPU scheduling algorithm.

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:

EXPECTED VIVA QUESTIONS:


Q.1 What is FCFS algorithm?
Q.2 When is CPU Scheduling?

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:

1. Start the process


2. Get the number of processes to be inserted
3. Sort the processes according to the burst time and allocate the one with shortest burst to execute
first
4. If two processes have same burst length then FCFS scheduling algorithm is used
5. Calculate the total and average waiting time and turnaround time
6. Display the values
7. Stop the process

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 What is ready queue
Q.2 When is scheduler?

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:

1. Start the process


2. Get the number of processes to be inserted
3. Get the corresponding priority of processes
4. Sort the processes according to the priority and allocate the one with highest priority to execute
first
5. If two processes have same priority then FCFS scheduling algorithm is used
6. Calculate the total and average waiting time and turnaround time
7. Display the values
8. Stop the process

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1What is long term scheduler?
Q.2What is priority scheduling?

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:

EXPECTED VIVA QUESTIONS:


Q.1 What is preemptive scheduling?
Q.2 what is time slice in scheduling?

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:

(1) The producer must first create a new widget.


(2) Then, it checks to see if the buffer is full. If it is, the producer will put itself to sleep until the
consumer wakes it up. A "wakeup" will come if the consumer finds the buffer empty.
(3) Next, the producer puts the new widget in the buffer. If the producer goes to sleep in step
(2), it will not wake up until the buffer is empty, so the buffer will never overflow.
(4) Then, the producer checks to see if the buffer is empty. If it is, the producer assumes that the
consumer is sleeping, an so it will wake the consumer. Keep in mind that between any of
these steps, an interrupt might occur, allowing the consumer to run.
(1) The consumer checks to see if the buffer is empty. If so, the consumer will put itself to sleep
until the producer wakes it up. A "wakeup" will occur if the producer finds the buffer empty
after it puts an item into the buffer.
(2) Then, the consumer will remove a widget from the buffer. The consumer will never try to
remove a widget from an empty buffer because it will not wake up until the buffer is full.
(3) If the buffer was full before it removed the widget, the consumer will wake the producer.
(4) Finally, the consumer will consume the widget. As was the case with the producer, an
interrupt could occur between any of these steps, allowing the producer to run.

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 What is critical section?
Q.2 What is concurrent execution?

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

Functions for sempahore :


– wait() : decrements the semaphore value.
– signal() : increments the semaphore value.

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 {

// Reader wants to enter the critical section


wait(mutex);

// The number of readers has now increased by 1 readcnt+


+;

// there is atleast one reader in the critical section


// this ensure no writer can enter if there is even one reader
// thus we give preference to readers here
if (readcnt==1)
wait(wrt);
// other readers can enter while this current reader is inside
// the critical section
signal(mutex);

// current reader performs reading here


wait(mutex); // a reader wants to leave

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:

EXPECTED VIVA QUESTIONS:


Q.1 What is critical region?
Q.2 what is mutual exclusion and progress?
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.7
Unit/Topic: 4/IPC
PROBLEM DEFINITION:
Write a program to implement classical inter process communication problem (Dining Philosophers).

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:

EXPECTED VIVA QUESTIONS:


Q.1 What is busy waiting in process synchronization?
Q.2 what is deadlock?

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

2. Declare the size with respect to page length

3. Check the need of replacement from the page to memory

4. Check the need of replacement from old page to new page in memory

5. Forma queue to hold all pages

6. Insert the page require memory into the queue

7. Check for bad replacement and page fault

8. Get the number of processes to be inserted

9. Display the values

10. Stop the process

LRU Algorithm

1. Start the process

2. Declare the size

3. Get the number of pages to be inserted

4. Get the value

5. Declare counter and stack

6. Select the least recently used page by counter value


7. Stack them according the selection.

8. Display the values

9. Stop the process

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 What is demand paging?
Q.2 what is swapping?

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:

To understand various Disk & Drum scheduling Algorithms


ALGORITHM:
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.

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 What disk scheduling?
Q.2 what is seek time and rotational latency?

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:

1. Start the program.


2. Get the values of resources and processes.
3. Get the avail value.
4. After allocation find the need value.
5. Check whether its possible to allocate.
6. If it is possible then the system is in safe state.
7. Else system is not in safety state.
8. If the new request comes then check that the system is in safety.
9. or not if we allow the request.
10. stop the program.
11. end

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 What is deadlock avoidance?
Q.2 what is deadlock detection?

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 client stub is called by the client.


• The client stub makes a system call to send the message to the server and puts the
parameters in the message. • The message is sent from the client to the server by the
client’s operating system.
• The message is passed to the server stub by the server operating system.
• The parameters are removed from the message by the server stub.
• Then, the server procedure is called by the server stub.

A diagram that demonstrates this is as follows:

Advantages of Remote Procedure Call


Some of the advantages of RPC are as follows:
• Remote procedure calls support process oriented and thread oriented models.
• The internal message passing mechanism of RPC is hidden from the user.
• The effort to re-write and re-develop the code is minimum in remote procedure calls.
• Remote procedure calls can be used in distributed environment as well as the local
environment.
• Many of the protocol layers are omitted by RPC to improve performance.

Disadvantages of Remote Procedure Call


Some of the disadvantages of RPC are 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:

EXPECTED VIVA QUESTIONS:


Q.1 What is RPC?
Q.2 what is the need of RPC?

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.

Device Driver Types – Kernel & User Drivers

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:

1. Kernel Device Drivers


2. User Device Drivers
Kernel Device Drivers are the generic device drivers that load with the operating system into the
memory as part of the operating system; not the entire driver but a pointer to that effect so that the
device driver can be invoked as soon as it is required. The drivers are pertaining to BIOS,
motherboard, processor, and similar hardware form part of Kernel Software.
A problem with Kernel Device Drivers is that when one of them is invoked, it is loaded into the
RAM and cannot be moved to page file (virtual memory). Thus, a number of device drivers running
at the same time can slow down machines. That is why there is a minimum system requirement for
each operating system. The different operating systems already add up the resources needed for
kernel device drivers, so that end users need not worry about extra memory requirements.

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:

EXPECTED VIVA QUESTIONS:


Q.1 What is device driver?
Q.2 what is system call?

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:

EXPECTED VIVA QUESTIONS:


Q.1 What is waiting time?
Q.2 what is turnaround time?

NAME OF FACULTY:
SIGNATURE:
DATE:

You might also like