Processes etc.
Processes and Concurrency
Consider the following C program:
#include <stdio.h>
#include <unistd.h>
int main() {
char* words[] = {"Let's", "go", "CS", "105!"};
for (int i = 0; i < 4; ++i) {
pid_t pid = fork();
if (pid == 0) {
printf("%s ", words[i]);
return i+1;
}
}
sleep(2);
printf("\nBye!\n");
return 0;
}
When considering this code, assume that the fork system call always succeeds, that the scheduler can interleave the execution of the parent and child processes in any way, and that the children run quickly enough that they will be done by the time the parent wakes up from sleep.
If any part suggests a change to the program, the program is reset to its original form before the next part.
(When logged in, completion status appears here.)