- 论坛徽章:
- 0
|
[root@localhost demo]# cat fork.c
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
pid_t child;
if(!(child=fork()))
{
printf (" in child ");
_exit(0);
}
printf("\n prient pid -- child pid %d\n",child);
return 0;
}
编译后执行,没有显示in child 这句
[root@localhost demo]# ./a.out
prient pid -- child pid 3465
而在printf (" in child ");改成printf (" \nin child \n");后,可以显示
[root@localhost demo]# ./a.out
in child
prient pid -- child pid 3465
请教大家,为什么不能显示,难道是_exit函数的作用?还有资料上说fork()返回值是随机的,但我试了很多边,都是先打印子进程,再打印父进程,难道是平台的缘故?(我用的是AS 4)?? |
|