Starting from:

$30

Operating Systems - Homework #3

1
CS342 -

Homework #3

This homework is for you to exercise and learn. The questions will be graded
selectively (that means not all questions will be graded).
Q1. Write a C program that will define a global integer array of size 1000 and will
initialize it with random values. Then it will create 3 threads. Threads will run
concurrently. The first thread will find the average, the second thread will find the
minimum, and the third thread will find the maximum value in the array. The main
thread will then print these 3 values out.
Q2. Consider the following structure definition.
struct student {
int id;
char name[64];
char lastname[64];
int age;
double cgpa;
};
Write a producer program and a consumer program. You will use shared memory to
pass student information from the producer to the consumer for 3 students. You can
set the values for the students to anything you like. You will use POSIX shared
memory API. Learn more about it by typing “man shm_overview” at Linux command
line.
Note that if shmptr is a variable pointing to some location in the shared memory, then
you can put (write) student information into that location as below. You can use a
similar approach for getting (reading) the information.
struct student *sp;
sp = (struct student *) shmptr;
sp-id = 1045;
strcpy (sp-name, “Ali”);
….
Q3. Assume for a program, the fraction of the program that must run serially is 0.25.
What is the maximum speed up that we can achieve for that program if we use 8
processors (8 threads)? What is the limit?
Q4. Consider the following 5 processes and their arrival and CPU times.
Arrival time CPU time (CPU burst length)
A 0 50
B 15 80
2
C 35 40
D 55 20
E 65 50
Assume that in case of a tie, a process with lower ID enters the ready-queue first. A
has lower ID than B, for example.
For each of the following scheduling algorithms, find out the finish time and total
waiting time in the ready queue for each process.
a) RR scheduling with q = 30 ms.
b) RR scheduling with q = 10 ms.
c) RR scheduling with q = very very small (much smaller than 1, i.e., close to 0;
perfect sharing).
d) SRJF.
e) FCFS.
Q5. Assume initial estimation is 20 ms for bursts of a process. What would be the
estimate after 3 bursts of lengths 24, 18, and 30, assuming alpha = 0.4. 

More products