For the homework questions below, if you believe that you cannot answer a question without making some assumptions, state those assumptions in your answer.
#include <signal.h>
#include <sys/wait.h>
main {
for ( ; ; ) {
if (! fork() ) { exit(0); }
sleep(1);
}
}
#include <stdlib.h>
int main (int argc, char *arg[])
{
fork ();
if (fork ()) {
fork ();
}
fork ();
}
Draw a tree diagram showing the hierarchy of processes created when the program executes. How many total processes are created (including the first process running the program)?
Hint: You can always add debugging code, compile it, and run the program to experiment with what happens.
struct lock {
...
}
void acquire (struct lock *) {
...
}
void release (struct lock *) {
...
}
Hints: You will need two binary semaphores to implement one counting semaphore. There is no need to use a queue — the queueing on the binary semaphores is all you'll need. You should not use busy waiting. The wait() operation for the counting semaphore will first wait on one of the two binary semaphores, and then on the other. The wait on the first semaphore implements the queueing on the counting semaphore and the wait on the second semaphore is for mutual exclusion.