我想请问一下为什么我运行这个程序没有结果直接退出??
# include<unistd.h>
# include<signal.h>
# include<stdio.h>
int pid1,pid2;
int main(void)
{
int fd[2];
char OutPipe[100],InPipe[100];
pipe(fd);
while((pid1=fork())= = -1);
if(pid1= =0)
{
lockf(fd[1],1,0);
sprintf(OutPipe,“child 1 process is sending message!”);
write(fd[1],OutPipe,50);
sleep(5);
lockf(fd[1],0,0);
exit(0);
}else{
while((pid2=fork())= = -1);
if(pid2= =0)
{
lockf(fd[1],1,0);
sprintf(OutPipe,“child 2 process is sending message!”);
write(fd[1],OutPipe,50);
sleep(5);
lockf(fd[1],0,0);
exit(0);
}else{
wait(0);
read(fd[0],InPipe,50);
printf(“%s\n”,InPipe);
wait(0);
read(fd[0],InPipe,50);
printf(“%s\n”,InPipe);
exit(0);
}
}
}
# include<signal.h>
# include<stdio.h>
int pid1,pid2;
int main(void)
{
int fd[2];
char OutPipe[100],InPipe[100];
pipe(fd);
while((pid1=fork())= = -1);
if(pid1= =0)
{
lockf(fd[1],1,0);
sprintf(OutPipe,“child 1 process is sending message!”);
write(fd[1],OutPipe,50);
sleep(5);
lockf(fd[1],0,0);
exit(0);
}else{
while((pid2=fork())= = -1);
if(pid2= =0)
{
lockf(fd[1],1,0);
sprintf(OutPipe,“child 2 process is sending message!”);
write(fd[1],OutPipe,50);
sleep(5);
lockf(fd[1],0,0);
exit(0);
}else{
wait(0);
read(fd[0],InPipe,50);
printf(“%s\n”,InPipe);
wait(0);
read(fd[0],InPipe,50);
printf(“%s\n”,InPipe);
exit(0);
}
}
}
...全文
相关推荐
docker容器运行后退出(怎么才能一直运行)
主要介绍了docker容器运行后退出(怎么才能一直运行),本文详细的介绍了解决方法,非常具有实用价值,需要的朋友们下面随着小编来一起学习学习吧
pycharm运行程序时看不到任何结果显示的解决
原因是用程序选择了console来运行,取消console方法如下: Run->Edit Configurations 取消run with python console的勾 补充拓展:解决pycharm运行后不显示run的结果问题 1:函数结果未通过print进行输出,修改后:print (函数名()) 2:取消Run with python console 以上这篇pycharm运行程序时看不到任何结果显示的解决就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持软件开发网。 您可能感兴趣的文章:postman和
两种退出程序方法
点击按钮,弹出对话框退出程序;点击返回键,再按一次退出程序。新手上路,方便刚接触Android的同学参考
Android安卓app 让程序假退出,仍在后台运行.zip
Android安卓app 让程序假退出,仍在后台运行.zip
如何在微信小程序里面退出小程序的方法
主要介绍了如何在微信小程序里面退出小程序的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧


