wait函数求解,谢谢

stardust20 2010-05-20 02:06:02
这是一本入门教程中的代码,在ubuntu可以正确运行,可是wait(pid);,wait的参数应该是int *的为什么传pid_t编译运行,竟然没报错。而且就算没有包含任何头文件,在我的机子上,wait(1)这种看起来很奇怪的语句都能编译并且运行。。这是什么回事。。希望大侠帮忙解释下。。谢谢

#include <stdio.h>
#include <unistd.h>
#include <wait.h>
#include <sys/types.h>
int main()
{
int data=0;
pid_t pid;
int choose=0;
while ((choose=getchar())!='q')
{
switch(choose)
{
case '1':
pid=fork();
if(pid < 0)
{
printf("Error !\n");
}
if (pid == 0)
{
data++;
exit(0);
}
wait(pid);
if (pid > 0)
{
printf("data is %d\n",data);
}
break;
case '2':
pid=vfork();
if (pid < 0)
{
perror("error !\n");
}
if (pid == 0)
{
data++;
exit(0);
}
wait(pid);//这边感觉有问题。。。
if (pid > 0)
{
printf("data is%d\n",data);
}
break;
default:
break;
}
}
}
...全文
194 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
stardust20 2010-05-20
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 pottichu 的回复:]
fedora 系列,
CentOS 系列。
[/Quote]
万分感谢
pottichu 2010-05-20
  • 打赏
  • 举报
回复
fedora 系列,
CentOS 系列。
stardust20 2010-05-20
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 pottichu 的回复:]

开发的话, 还是不要用 ubuntu 了。。。。
[/Quote]
哦哦。。那一般用什么版本呢?帮忙推荐个,万分感谢。
pottichu 2010-05-20
  • 打赏
  • 举报
回复
开发的话, 还是不要用 ubuntu 了。。。。
piedgogo 2010-05-20
  • 打赏
  • 举报
回复
额,lz好神奇的gcc。。。
stardust20 2010-05-20
  • 打赏
  • 举报
回复
谢谢。。两位大侠帮我试了。。。我的是gcc version 4.4.1 。。。好无语呀。。我也想着他调不通的。。
pottichu 2010-05-20
  • 打赏
  • 举报
回复
p.c: In function ‘main’:
p.c:23: 警告:隐式声明与内建函数 ‘exit’ 不兼容
p.c:25: 错误:实参 1(属于 ‘wait’)类型不兼容
p.c:40: 警告:隐式声明与内建函数 ‘exit’ 不兼容
p.c:42: 错误:实参 1(属于 ‘wait’)类型不兼容


人品问题阿。。。。

PS: 你的 gcc 是虾米版本?
太乙 2010-05-20
  • 打赏
  • 举报
回复
test.cpp: In function `int main()':
test.cpp:26: error: invalid conversion from `pid_t' to `void*'
test.cpp:26: error: initializing argument 1 of `__pid_t wait(void*)'
test.cpp:43: error: invalid conversion from `pid_t' to `void*'
test.cpp:43: error: initializing argument 1 of `__pid_t wait(void*)'

23,124

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧