Consider a program using the fork and exec system calls shown below. Assume that the code shown below executes correctly, and that the fork and exec system calls succeed. The exec system call (invoked via the “execv” function) correctly runs the sleep command to sleep for $1$ second.
#include <studio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
void main(int argc, char **argv) {
int rc;
int a = 0;
rc = fork();
if(rc == 0) {
char *const exec_arg[] = {"/bin/sleep", "1", NULL};
execv(exec_arg[0], exec_arg);
printf("a=%d\n", a);
}
else {
a++;
wait(NULL);
printf("a=%d\n", a);
}
}
Which of the following is/are possible output when this program is executed?
- $\textsf{a = 0}\\
\textsf{a = 1}$
- $\textsf{a = 1}\\
\textsf{a = 0}$
- $\textsf{a = 1}$
- $\textsf{a = 0}$