1.
Answer the following questions
a)Explain the use of fork() system call.
b)Assuming fork() is successful, how many times will the message “Hello!\n” be displayed?
main() {
int a = 0;
int pid = fork();
a++;
if (pid == 0) {
pid = fork();
a++;
} else {
a++;
}
printf(“Hello!\n”);
printf(“a is %d\n”, a);
}
c)Using the program below, identify the values of pid at lines A, B, C, and D. (Assume that the actual pids of the parent and child are 2810 and 2713, respectively.)
#include
#include
#include
int main(){
pid_t pid, pid1;
/* fork a child process */
pid = fork();
if (pid
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0) { /* child process */
pid1 = getpid();
printf("child: pid = %d",pid); /* A */
printf("child: pid1 = %d",pid1); /* B */
}
else { /* parent process */
pid1 = getpid();
printf("parent: pid = %d",pid); /* C */
printf("parent: pid1 = %d",pid1); /* D */
wait(NULL);
}
return 0;
}
2.In class, we discussed various CPU scheduling algorithms,list 2scheduling algorithms could result in starvation.
3.Consider the following set of processes, with the length of the CPU burst time given in milliseconds:
Process
|
Burst Time
|
Priority
|
Arrival Time
|
P1
|
10
|
5
|
0
|
P2
|
7
|
3
|
2
|
P3
|
10
|
1
|
3
|
P4
|
11
|
4
|
4
|
P5
|
4
|
1
|
45
|
a)Draw two Gantt charts that illustrate the execution order of these processes using the following scheduling algorithms: preemptive SJF and RR (quantum = 4).
b)What is the turnaround time of each process for each of the scheduling algorithms in part a)? and show the average turnaround time.
c)What is the waiting time of each process for each of these scheduling algorithms in part a)? and show the average waiting time.
d)What is the response time of each process for each of these scheduling algorithms in part a)? and show the average response time.
e)Which of the algorithms results in the minimum average waiting time (over all processes)?
f)With Round Robin scheduling algorithm, a short quantum allows a scheduler to cycle through more processes more quickly than with a long quantum. What is the downside of this?
4.What are two differences between user-level threads and kernel-level threads? Under what circumstances is one type better than the other?