I have 2 programs and I'm very confused on the return of fork() in child process
The first program would call fork()
and assign it to p
. When p == 0
, it implies child process.
// The first program
p = fork();
if (p == 0)
{
// child process
}
else
{
// parent process or exception
}
But what if we just call fork() == 0
?
I would think fork()
return non-zero
from it's docs.
Hence the condition is never executed.
// The second program
if (fork() == 0)
{
// Would this ever be reached?
printf("A\n");
}
printf("B\n");