(no subject)

Apr 08, 2007 02:03

2. 76 seconds in the 6th level queue.
1) 200-4 =196
2) 196-8 =188
3) 188-16=172
4) 172-32=140
5) 140-64=76
6) 76-128=-52
3a. (36-20)+(36-18)+(32-18)+(32-24)+(24-16)+(16-12)+(26-12)+(30-26) = 94
3b. (20-18)+(18-16)+(16-12)+(24-12)+(26-24)+(30-26)+(32-30)+(36-32) = 32
3c. (24-20)+(26-24)+(30-26)+(32-30)+(36-32)+(36-18)+(18-16)+(16-12) = 38
4a. If q > T, then the sum of S is 0 and efficiency approaches 100%.
4b. If S < q < T, then efficiency is T(1+(S/q))
4c. If q is nearly 0 then S becomes an overwhelming value as T is constantly shifted in and out of context, allowing efficiency to approach 0%.
5. C finishes first, in 10 minutes. It's original run time is estimated at 2 minutes, but due to the fair sharing of the CPU over 5 processes it takes 5 times as long to complete.
The next process to finish is D at 8 minutes after C finishes, for a total of 18 minutes. During the first 10 minutes of run time, 2 minutes of the projected run time were processed along side 4 other processes. After C finishes, D shares the CPU with 3 other processes giving a speed at 1/4th maximum. 2 minutes of stimated run time are left, at 1/4th speed taking 8 minutes. Totalling 18 minutes.
The trend continues as that total run times are: C@10m, D@18m, B@24m, E@28m, and A@30m. (A+B+C+D+E)/5 = 22 minutes average run time.
6a. No, it would not. As both R and S are currently held by A, neither resource can be given to C and possibly create a deadlock.
6b. No, for the same reasons as requesting S instead of R. Both resources are held.
7a. No. If Suzanne is granted anothter unit there would not be enough free unit to satisfy any other person's full amount of withdrawl.
7b. Yes. With one free unit left the banker is still able to satisfy, with Marvin ending up as the one to be satisfied first.
8. Yes, A needs only one more tape drive to reach it's maximum allotment. Afterwhich when it's drives are released, all other processes may be satisfied.
9. The system is deadlock free at the maximum of N=1. While there are 6 available tape drives, if two processes are vying for the same two with each process holding a tape drive dead lock will occur.
Alternately, if the tape drive content is unsignificant then at N=3 each process could hold 2 tape drives each without fear of stepping on each others toes.
10a. (i1,i1) to (i2,i6)
10b. No, as processes cannot run backwards and the shaded regions cannot be entered, there's no way for (i3, i7) to be reached.
10c.
10d. Multiple processor or symmetric processing.

11.
### proj2-11.c
#include
int main(void) {
int cpid;
if( (cpid = fork()) < 0) {
printf("forking failed.");
} else if( cpid == 0 ) {
int pid = getpid();
printf("Child(%d) sleeping...\n", pid); fflush(stdout);
sleep(5);
printf("Child(%d) awakens...\n", pid); fflush(stdout);
} else {
printf("Parent of %d waiting...\n", cpid); fflush(stdout);
wait(cpid);
printf("Parent of %d done waiting...\n", cpid); fflush(stdout);
}
}
### proj2-11
Child(3721) sleeping...
Parent of 3721 waiting...
Child(3721) awakens...
Parent of 3721 done waiting...

12a.
### proj2-12a.c
#include
int main(void) {
printf("Sleep #1\n");
sleep(1);
printf("Sleep #2\n");
sleep(1);
printf("Sleep #3\n");
sleep(1);
printf("Sleep #4\n");
sleep(1);
printf("Sleep #5\n");
sleep(1);
printf("Program exiting.\n");
}
### proj2-12a // ^C after sleep #2
Sleep #1
Sleep #2

12b. My OS (GNU/Linux 2.6.20) ignores all ^C input after the signal trap is created.
### proj2-12b.c
#include
#include
int main(void) {
signal(SIGINT, SIG_IGN);
printf("Sleep #1\n");
sleep(1);
printf("Sleep #2\n");
sleep(1);
printf("Sleep #3\n");
sleep(1);
printf("Sleep #4\n");
sleep(1);
printf("Sleep #5\n");
sleep(1);
printf("Program exiting.\n");
}
### proj2-12b
Sleep #1
Sleep #2
Sleep #3
Sleep #4
Sleep #5
Program exiting.

12c. Hitting ^C during a sleep call ended the sleep and called the handler., then prooceeded from that point on in the code.
### proj2-12c.c
#include
#include
void sig_catch(int sig_num) {
signal(SIGINT, sig_catch);
printf("Signal %d caught.\n", sig_num);
fflush(stdout);
}

int main(void) {
signal(SIGINT, sig_catch);
printf("Sleep #1\n");
sleep(1);
printf("Sleep #2\n");
sleep(1);
printf("Sleep #3\n");
sleep(1);
printf("Sleep #4\n");
sleep(1);
printf("Sleep #5\n");
sleep(1);
printf("Program exiting.\n");
}
### proj2-12c
Sleep #1
Signal 2 caught.
Sleep #2
Signal 2 caught.
Sleep #3
Signal 2 caught.
Sleep #4
Signal 2 caught.
Sleep #5
Signal 2 caught.
Program exiting.

13.
### proj2-13.c
#include
#include
void sig_catch(int sig_num) {
signal(SIGALRM, sig_catch);
printf("\nInput timeout.\n");
fflush(stdout);
kill(getpid(), SIGINT);
}

int main(void) {
char blah[128];
signal(SIGALRM, sig_catch);
printf("Please provide meaningless input:");
fflush(stdout);
alarm(10);
printf("%d %s\n", fgets(blah, 128, stdin), blah);
fflush(stdout);
}
### proj2-13
Please provide meaningless input:
Input timeout.
Previous post Next post
Up