Studying for finals, I got stuck on this problem. They ask how many times the following code executes printf:
#include "csapp.h"
void doit() {
Fork();
Fork();
printf("hello\n");
return;
}
int main()
{
doit();
printf("hello\n");
exit(0);
}
The solutions say that it printf executes 8 times, but I cannot figure out why. I've been trying to draw the picture of what's going on in the code, but my pictures make it seem like it only execute 4 times.
2 forks - Four processes. Each process has two printfs with hello (one in main and one in doit - hence 8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With