找回密码
 注册
查看: 1014|回复: 2

client 和server可以调换吗?高手快帮忙

[复制链接]
发表于 2003-11-4 21:21:44 | 显示全部楼层 |阅读模式
一个消息的创建程序是这样的:那么为何程序中server在前,而client 在后;
如果在输程序中将二者交换时,为何结果如此奇怪???
交替出现是为什么?
#include <unistd.h>
#include &lt;signal.h&gt;
#include &lt;stdio.h&gt;
int pid1=0,pid2=0;
int EndFlag=0;
void IntDelete()
{
   kill(pid1,16);
   kill(pid2,17);
   EndFlag=1;
}
void Int1()
{
printf("child process 2 is killed! by parent \n");
exit(0);
}
void Int2()
{
printf("child process 2 is killed !by parent \n");
exit(0);
}
main()
{
int exitpid;
signal(SIGINT,SIG_IGN);
signal(SIGQUIT,SIG_IGN);
while ((pid1=fork())==-1);
if (pid1==0)
{
signal(SIGUSR1,Int1);
signal(SIGINT,SIG_IGN);
pause();
exit(0);
}
else
{
while((pid2=fork())==-1);
if (pid2==0)
{
signal(SIGUSR1,Int2);
signal(SIGINT,SIG_IGN);
pause();
exit(0);
}
else
{
signal(SIGINT,IntDelete);
waitpid(-1,&amp;exitpid,0);
printf("parent process is killed \n");
exit(0);
}
}
}
发表于 2003-11-25 21:54:27 | 显示全部楼层
注意他们的通信机制!!!
回复

使用道具 举报

发表于 2004-1-29 16:26:54 | 显示全部楼层
u have not describ ur problem clearly, but the sequence of process execution is not depend on the sequence u type in. maybe i am wrong, sorry not to help u
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-7-5 11:06 , Processed in 0.040347 second(s), 16 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表