I have already asked one question about fork(), here is another. Given the following code:
#include <unistd.h>
#include <stdio.h>
int main()
{
pid_t pid1, pid2;
pid1 = fork();
pid2 = fork();
if (pid1 != 0 && pid2 != 0)
printf("A\n");
if (pid1 != 0 || pid2 != 0)
printf("B\n");
exit(0);
}
After the second fork()
, what would be the values of pid1
& pid2
?
As far as understood, first fork sets the pid1 > 0
and would be identical in all children created later on. However, what would happen to pid2
??
Thanks !