Child and Parent pid with fork();
问题 I'm trying to make a program which make 9 child process, so I use fork 9 times only if we are the father, like this: for (int i = 0; i < 9; i++) { // Creo 9 hijos. if (child_pid > 0) { child_pid = fork(); childs[i] = child_pid; } if (child_pid < 0) printf("Error...\n"); } Now, I have to print on each children what children he is, starting from 0, so I was thinking about this: printf("This is child #%d\n", getpid() - getppid()); But I'm not sure, Does this always work?, What if while the