|
|
发表于 2005-11-4 21:18:10
|
显示全部楼层
最后那个return 0;执行不到吧,前面都exit(0)了。
Post by cqulzg
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<stdio.h>
int main()
{
pid_t pid1,pid2;
if ((pid1=fork())<0)
{
printf("fork error!\n");
exit(0);
}
else if (pid1==0)
{
if ((pid2=fork())<0)
{
printf("fork error!\n");
exit(0);
}
else if (pid2>0)
exit(0);
else
{
sleep(2);
printf("this is grandson,parent pid is :%d\n",getpid());
exit(0);
}
}
else
{
printf("this is the grandpa process,pid is %d\n",getpid());
exit(0);
}
if (waitpid(pid1,NULL,0)!=pid1)
exit(0);
printf("this is grandson,parent pid is :%d\n",getpid());
exit(0);
return 0;
}
---------------------------------------------------------------------------------------
[root@localhost cpro]# gcc wait.c
wait.c: 在函数 ‘main’ 中:
wait.c:11: 警告:内建函数 ‘exit’ 不兼容的隐式声明
wait.c:18: 警告:内建函数 ‘exit’ 不兼容的隐式声明
wait.c:21: 警告:内建函数 ‘exit’ 不兼容的隐式声明
wait.c:32: 警告:内建函数 ‘exit’ 不兼容的隐式声明
wait.c:35: 警告:内建函数 ‘exit’ 不兼容的隐式声明
在编译的时候出现上面的提示,请问这个是什么原因,是不是exit 函数出了问题?
但是我在编译另外的程序上也用了exit,编译没有问题阿 。。。 |
|