I have such a short code example, it was given to us to demonstrate the operation of the fork () function:
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> int main () { pid_t pid; pid = fork(); pid = fork(); printf("Fork-Test\n"); return EXIT_SUCCESS; } I do not quite understand the result. As a result, I have 4 times wrote Fork-Test in the terminal. I don’t understand, first, why it happens more than once, because I call the printf("Fork-Test\n"); method printf("Fork-Test\n"); only once, secondly, once already several times, why exactly 4? Moreover, in the following form:
Fork-Test Fork-Test Process returned 0 (0x0) execution time : 0.007 s Press ENTER to continue Fork-Test Fork-Test I do not understand the meaning. I will be grateful for any explanations about fork()