You are on page 1of 3

CSE 2005 – Operating Systems Lab

Final Assessment Test

1. Write a multithreaded program that calculates various statistical values for a list of numbers. This
program will be passed a series of numbers on the command line and will then create three separate
worker threads. One thread will determine the average of the numbers, the second will determine
the maximum value, and the third will determine the minimum value. For example, suppose your
program is passed the integers
90 81 78 95 79 72 85
The program will report
The average value is 82
The minimum value is 72
The maximum value is 95
The variables representing the average, minimum, and maximum values will be stored globally.
The worker threads will set these values, and the parent thread will output the values once the
workers have exited.
(The students with following register numbers have to solve the above 19BCB0146,
19BCE0052, 19BCE0124, 19BCE0458, 19BCE0733, 20BCB0014, 20BCB0137,
20BCE0121, 20BCE0187, 20BCE0257)

2. The Collatz conjecture concerns what happens when we take any positive integer n and
apply the following algorithm:

n = n/2, if n is even
n = 3 × n + 1, if n is odd
The conjecture states that when this algorithm is continually applied, all positive integers
will eventually reach 1. For example, if n = 35, the sequence is 35, 106, 53, 160, 80, 40,
20, 10, 5, 16, 8, 4, 2, 1.Write a C program using the fork () system call that generates this
sequence in the child process. The starting number will be provided from the command
line. For example, if 8 is passed as a parameter on the Command line, the child process
will output 8, 4, 2, 1. Because the parent and child processes have their own copies of the
data, it will be necessary for the child to output the sequence. Have the parent invoke the
wait () call to wait for the child process to complete before exiting the program.
(The students with following register numbers have to solve the above 20BCE0387,
20BCE0535, 20BCE0639, 20BCE0645, 20BCE0736, 20BCE0772, 20BCE0807,
20BCE0817, 20BCE0917, 20BCE0929, 20BCE0986)
3. The Crisp Cafe in the strip mall near my house serves customers FIFO in the following
way. Each customer entering the shop takes a single “ticket” with a number from a
“sequencer” on the counter. The ticket numbers dispensed by the sequencer are guaranteed
to be unique and sequentially increasing. When a barista (a person who makes and serves
coffee) is ready to serve the next customer, it calls out the “event count”, the lowest
unserved number previously dispensed by the sequencer. Each customer waits until the
event count reaches the number on its ticket. Each barrista waits until the customer with
the ticket it called places an order.

Implement sequencers, tickets, and event counts using mutexes and condition variables.
Your solution should also include code for the barrista and customer threads.
(The students with following register numbers have to solve the above 20BCE2013,
20BCE2023, 20BCE2029, 20BCE2095, 20BCE2207, 20BCE2312, 20BCE2334,
20BCE2366, 20BCE2374, 20BCE2378, 20BCE2383)

4. A tribe of savages eats communal dinners from a large pot that can hold M servings of
stewed missionary1. When a savage wants to eat, he helps himself from the pot, unless it
is empty. If the pot is empty, the savage wakes up the cook and then waits until the cook
has refilled the pot. Any number of savage threads runs the following code:

Unsynchronized savage code

And one cook thread runs this code:

The synchronization constraints are:


Savages cannot invoke getServingFromPot if the pot is empty.
The cook can invoke putServingsInPot only if the pot is empty.
Add code for the savages and the cook that satisfies the synchronization constraints.

(The students with following register numbers have to solve the above 20BCE2516,
20BCE2552, 20BCE2618, 20BCE2801, 20BCE2838, 20BCE2852, 20BCE2872,
20BCE2961, 20BCI0055, 20BCI0124, 20BCI0125)
5. Consider a memory hole of size 1kb initially. When a sequence of memory request arrives
as following, illustrate the memory allocation by various approaches and calculate the total
amount memory wasted by external fragmentation and internal fragmentation in each
approach.

100k 300k 400k 200k 100k 800k 500k


Memory requests are 200k, 350k, 250k, 100k, 70k, 650k, 400k
a. First fit;
b. Best fit
c. Worst fit
(The students with following register numbers have to solve the above 20BCI0134,
20BCI0162, 20BCI0179, 20BCI0180, 20BCI0220, 20BCI0236, 20BCI0247,
20BCI0260, 20BCI0261, 20BCI0269, 20BCI0274)

6. Consider a file of size 1 MB. The size of a disk block is 512Bytes. Assume any number
of available free blocks in the disk contiguously or non-contiguously. Implement the
following algorithms to perform file allocation. Determine the efficiency of each file
allocation strategies.

a. Sequential
b. Indexed
c. Linked
(The students with following register numbers have to solve the above 20BCI0277,
20BCI0296, 20BCI0307, 20BCI0308, 20BCI0324, 20BDS0182, 20BDS0322,
20BDS0386, 20BDS0401, 20BKT0095)

You might also like