Expert Answers

  1. Explain what happens when the following statements are executed x = 0; if ( x == fork()) printf(“CSC 389\n”);

2. Semaphores are used to control access to resources. Explain what happens when the following pseudo code is executed.

int sem1 0; int sem2 0; v(sem1); printf(“the v was executed\n”); p(sem2); printf(“the p was executed\n”);

3. Explain in detail what happens when each of the following statements are executed. You may assume all variables have been properly declared and this code.

int myfork, temp;        myfork = fork();  if (myfork > 0)        { wait(&temp);            exit(0); }

else          { printf(“the value of myfork is %d\n”, myfork);            exit(0); } //