2. Calculate number of times hello is printed.
#include <stdio.h>
#include <sys/types.h>
int main() {
fork();
fork();
fork();
printf("hello\n");
return 0;
}
The image above shows how the fork() calls will be executed in this case, and how many copies of each process will be made. Clearly, as shown above, there are a total of 8 calls made at the end. The printf() statement exists right at the end of the program hence it executes AFTER all the child processes have been created.
A brief summary:
When we execute the code above, we get:
Which establishes that the number of times the printf() statement is called is indeed 8.
Get Answers For Free
Most questions answered within 1 hours.