Title on a fork generated child process

 

Topics are as follows:

pid_t pid1,pid2;
pid1=fork();
pid2=fork();
if(pid1<0||pid2<0)
{
    printf("Fork Failed\n");
}
else
{
    printf("pid1: %d pid2: %d\n",pid1,pid2);
}
return 0;

Seeking final output:

This question is at that time did not distinguish, too much food, so the results should be launched,

First, figure out fork () return value in the parent process is a non-zero number, the child process is 0,

So pid1 can be divided into two non-zero value and 0,

(1) pid1 non-zero, PID2 Similarly there are two values, 0 or non-zero,

(2) pid1 is 0, indicating that the child, the same is pid2 two values ​​of 0 and 0

Fully result should be the last

x 0

xy

0 0

0 k

Or other order

Code results are as follows:

 

Guess you like

Origin www.cnblogs.com/JsonZhangAA/p/11374002.html