Part A: Disregarding questions of implementation, what is the difference between the abstract operations of a process relinquishing the CPU and a process being preempted? Hint: The definitions of the keywords relinquish and preempt are relevant, and the pseudocode and code referenced above illustrate the difference between these two words!
Part B: From what you know about context switching, and from the referenced part of some detail, what information must be included in the jump buffer used by longjmp(), and what information that the definition of longjmp() says may not be well defined must actually be saved and restored?
main() { int i; i = 0; if (fork()) { int j; for (j = 0;j < 1000; j++) { i++; } wait(); } else { int j; for (j = 0;j < 1000; j++) { i--; } exit(); } printf( "%d\n", i ); } main() { int i; jmp_buf b; i = 0; if (setjmp(b)) { int j; for (j = 0;j < 1000; j++) { i++; } } else { int j; for (j = 0;j < 1000; j++) { i--; } longjmp(b,1); } printf( "%d\n", i ); }Part A: Both the then and else clauses in both of these programs get executed. Explain why. It happens for different reasons with fork() and the setjmp()!
Part B: Why is the output of these two programs different?