- 论坛徽章:
- 1
|
回复 7# weishuo1999
谁胡说,你自己不试试看:
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t b; // note that the actual return type of fork is
// pid_t, though it's probably just an int typedef'd or macro'd
b = fork();
sleep(10); //应你要求加了sleep了
if (b == -1) perror("Fork failed");
else if (b > 0)
printf("from child\n"); // parent process
else
printf("from parent\n"); // child process
printf("The value of b is %d\n", b);
return 0;
}
结果:
from child
The value of b is 2151
from parent
The value of b is 0
|
|