您的位置:首页 > 运维架构 > Linux

读书笔记之linux/unix系统编程手册(26)

2015-08-24 19:19 721 查看
int main(int argc, char* argv[])
{

printf("hello world\n");
write(STDOUT_FILENO, "Ciao\n", 5);
int pid = fork();
if(pid == -1)
{
exit(0);
}else if(pid > 0)
{
int cid = wait(NULL);
printf("cid:%d\n", cid);

}else
{
int cid = wait(NULL);
printf("cid:%d\n", cid);
//_exit(0);

}
//both parent and children do below

return 0;
}


test@ubuntu:~/share/xinhaoliang$ ./a.out 

hello world

Ciao

cid:-1
cid:10192

wait在子进程中调用返回-1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: