实验代码就是:
int main(void)
{
pid_t child;
if((child=fork())==-1)
{
printf("Fork Error : %s\n", strerror(errno));
exit(1);
}
else
if(child==0) // 徨序殻
{
printf("I am the child process: %d\n", getpid());
exit(0);
}
else
{
printf("I am the father process:%d\n",getpid());
exit(0);//return 0;
}
}
执行时出现的现象就是:
clbiao@ubuntu:~/fork$ ./fork
I am the father process:4200
clbiao@ubuntu:~/fork$ I am the child process: 4201
可是我把程序交叉编译后下载进开发板运行又没有出现这样的现象,为什么?
现象正常:
# ./fork
I am the father process:4200
I am the child process: 4201
#