Consider the code:
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char **argv)
{
pid_t child;
if ((child = fork()) < 0) {
fprintf(stderr, "%s: fork of child failed: %s\n",
argv[0], strerror(errno));
exit(1);
} else if (child == 0) {
}
} else {
}
}
My question is: where does the child process come from in the code, i.e. which line is executed first? If he executes all the code, he will also create his own child process, and everything will happen continuously, which is not happening for sure!
If it starts after the fork () command, how does this happen if the statement first?
source
share