|
以下代码是基于linux系统的:
#include<sys/types.h>
#include<unistd.h>
main()
{
pid_t pid;
printf("before fork() ");
pid = fork();
if(pid<0)
{
printf("error \n");
}
else if(pid==0)
{
printf("this is child \n");
}
else if(pid>0)
{
printf("this is parent! \n");
}
}
|
#include<sys/types.h>
#include<unistd.h>
main()
{
pid_t pid;
printf("before fork() \n "); /*请注意这里*/
pid = fork();
if(pid<0)
{
printf("error \n");
}
else if(pid==0)
{
printf("this is child \n");
}
else if(pid>0)
{
printf("this is parent! \n");
}
}
|
大家可以分析一下这两段程序输出的结果分别是什么,并且说一下为什么会是这样。 |
|