Professional Documents
Culture Documents
Academic task- 3
Course Code: CSE 316 Course Title: Operating Systems Term: 16172
Important Points
QUESTIONS
1. There are 3 student processes and 1 teacher process. Students are supposed to do their
assignments and they need 3 things for that - pen, paper and question paper. The teacher
has an infinite supply of all the three things. One student has pen, another has paper and
another has question paper. The teacher places two things on a shared table and the
student having the third complementary thing makes the assignment and tells the teacher
on completion. The teacher then places another two things out of the three and again the
student having the third thing makes the assignment and tells the teacher on completion.
This cycle continues. Write a program to synchronize the teacher and the students.
2. Consider a scenario in which the scheduler allocates the CPU to processes in the ready
queue for a time slice of up to t milliseconds. If a process is not able to complete its
execution in t ms, it is interrupted and the scheduler proceeds to the next process in the
ready queue. The ready queue is to be treated as a circular queue. Assume that all the
processes arrived at time zero. Simulate this scenario by writing a program. The number
of processes, their burst time and time slice are to be taken as input from the user..
4. Consider a system consisting of p processes which arrive at different times. The process
that comes first is served first in a non-preemptive manner and preempt each process after
every 2 seconds. After that, the next arrived process is served by the CPU and this cycle
continues. Take the number of processes, burst times and arrival times as input from the
user and write a program to implement this type of scheduling.
5. Consider a scenario in which there are four page frames and eight pages. The frames are
initially empty. Write a program to find out the number of page faults if FIFO page
replacement is used. Take reference string as 0172327103.
6. Five processes A through E arrive in the system at almost the same time. They have
estimated running times of 10, 6, 2, 4 and 8 minutes. Their priorities are 3, 5, 2, 1 and 4
respectively, with 5 being the highest priority. Write a program to find out the mean
process turnaround time for – (a) priority scheduling and (b) FCFS scheduling.
7. Program a simulation of the banker’s algorithm. Your program should cycle through each
of the bank clients asking for a request and evaluating whether it is safe or unsafe. Output
a log of requests and decisions to a file.
8. Suppose that a disk drive has 5000 cylinders, numbered 0 to 4999. The drive is currently
serving a request at cylinder 143, and the previous request was at cylinder 125. The
queue of pending requests, in FIFO order, is 86, 1470, 913, 1774, 948, 1509, 1022, 1750,
130. Write a program to calculate the total distance (in cylinders) that the disk arm moves
to satisfy all the pending requests starting from the current head position for FCFS disk-
scheduling algorithm.
9. A uniprocessor system has n number of CPU intensive processes, each process has its
own requirement of CPU burst. The process with lowest CPU burst is given the highest
priority. A late-arriving higher priority process can preempt a currently running process
with lower priority. Simulate a scheduler that is scheduling the processes in such a way
that a higher priority process is never starved due to the execution of low priority
processes. What should be the average waiting time and average turnaround time if no
two processes are arriving at same time?
10. Write a program that detects if there is a deadlock in the system by using a resource
allocation graph. Your program should read from a file the following inputs: the number
of processes and the number of resources. For each process, it should read four numbers:
the number of resources it is currently holding, the IDs of resources it is holding, the
number of resources it is currently requesting, the IDs of resources it is requesting. The
output of your program should indicate if there is a deadlock in the system or not. In case
there is a deadlock in the system, the program should print out the identities of all
processes that are deadlocked.
11. Suppose that a disk drive has 5000 cylinders, numbered 0 to 4999. The drive is currently
serving a request at cylinder 143, and the previous request was at cylinder 125. The
queue of pending requests, in FIFO order, is 86, 1470, 913, 1774, 948, 1509, 1022, 1750,
130. Write a program to calculate the total distance (in cylinders) that the disk arm moves
to satisfy all the pending requests starting from the current head position for SSTF disk-
scheduling algorithm.
12. Write a program to implement priority scheduling algorithm with context switch time.
Prompt the user to enter the number of processes, their priority, burst time and arrival
time. Whenever a process is preempted and CPU's control is given to some other process
of higher priority, assume that it takes 2 seconds for context switching (dispatcher
latency). Simulate a scenario where the processes are assigned priority and a lower
priority number means higher priority. The priority of the waiting process increases at the
rate of 1 per 2 time units of wait. Calculate waiting time and turnaround time for each
process.
13. Design a scheduling program that is capable of scheduling processes that arrive in the
system at some time interval and are allocated the CPU for not more than 10 time units.
CPU must schedule processes having short execution time first. CPU is idle for first 3
time units and does not entertain any process prior to this time. Scheduler must maintain
a queue that keeps the order of execution of all the processes. Compute average waiting
and turnaround time.
14. There are 5 processes and 3 resource types, resource A with 10 instances, B with 5
instances and C with 7 instances. Consider the following and write a program to find out
whether the system is in safe state or not.
17. Consider a scheduler which schedules the job by considering the arrival time of the
processes where arrival time if given as 0 is discarded or displayed as error. The
scheduler implements the shortest job first scheduling policy, but checks the queue of the
processes after the every process terminates and time taken for checking and arranging
the process according to the shortest job is 2 time unit. Compute the waiting time,
turnaround time and average waiting time and turnaround time of the processes. Also
compute the total time taken by the processor to compute all the jobs.
The inputs for the number of requirements, arrival time and burst time should be
provided by the user.
Consider the following units for reference.
Process Arrival time Burst Time
1 0 6
2 3 2
3 5 1
4 9 7
5 10 5
6 12 3
7 14 4
8 16 5
9 17 7
10 19 2
18. Sudesh Sharma is a Linux expert who wants to have an online system where he can
handle student queries. Since there can be multiple requests at any time he wishes to
dedicate a fixed amount of time to every request so that everyone gets a fair share of his
time. He will log into the system from 10am to 12am only. He wants to have separate
requests queues for students and faculty. Implement a strategy for the same. The
summary at the end of the session should include the total time he spent on handling
queries and average query time.
19. Design a scheduler with multilevel queue having two queues which will schedule the
processes on the basis of pre-emptive shortest remaining processing time first algorithm
(SROT) followed by a scheduling in which each process will get 2 units of time to
execute. Also note that queue 1 has higher priority than queue 2. Consider the following
set of processes (for reference)with their arrival times and the CPU burst times in
milliseconds.
-------------------------------------
Process Arrival-Time Burst-Time
-------------------------------------
P1 0 5
P2 1 3
P3 2 3
P4 4 1
-------------------------------------
Calculate the average turnaround time and average waiting time for each process. The input for
number of processes and their arrival time, burst time should be given by the user.
20. Reena’s operating system uses an algorithm for deadlock avoidance to manage the
allocation of resources say three namely A, B, and C to three processes P0, P1, and P2.
Consider the following scenario as reference .user must enter the current state of system
as given in this example :
Suppose P0 has 0,0,1 instances , P1 is having 3,2,0 instances and P2 occupies 2,1,1
instances of A,B,C resource respectively.
Also the maximum number of instances required for P0 is 8,4,3 and for p1 is 6,2,0 and
finally for P2 there are 3,3,3 instances of resources A,B,C respectively. There are 3 instances
of resource A, 2 instances of resource B and 2 instances of resource C available. Write a
program to check whether Reena’s operating system is in a safe state or not in the following
independent requests for additional resources in the current state:
1. Request1: P0 requests 0 instances of A and 0 instances of B and 2 instances of C.
2. Request2: P1 requests for 2 instances of A, 0 instances of B and 0 instances of C.
All the request must be given by user as input.
21. A barbershop consists of a waiting roomwith n chairs and a barber room with one barber
chair. If there are no customers to be served, the barber goes to sleep. If a customer
entersthe barbershop and all chairs are occupied, then the customer leaves theshop. If the
barber is busy but chairs are available, then the customer sitsin one of the free chairs. If
the barber is asleep, the customer wakes upthe barber. Write a program to coordinate the
barber and the customers.Using synchronization tools like locks, semaphores and
monitorsprovide a solution to his problem.
22. Two types of people can enter into a library- students and teachers. After entering the
library, the visitor searches for the required books and gets them. In order to get them
issued, he goes to the single CPU which is there to process the issuing of books. Two
types of queues are there at the counter-one for students and one for teachers. A student
goes and stands at the tail of the queue for students and similarly the teacher goes and
stands at the tail of the queue for teachers (FIFO). If a student is being serviced and a
teacher arrives at the counter, he would be the next person to get service (PRIORITY-non
preemptive). If two teachers arrive at the same time, they will stand in their queue to get
service (FIFO). WAP to ensure that the system works in a non-chaotic manner.
If a teacher is being served and during the period when he is being served, another
teacher comes, then that teacher would get the service next. This process might continue
leading to increase in waiting time of students. Ensure in your program that the waiting
time of students is minimized.
---------------------------------------------------------------------------------------------------