23,124
社区成员
发帖
与我相关
我的任务
分享
#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;
}
}
}
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*)'