mp3 发表于 2003-11-4 21:21:44

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

一个消息的创建程序是这样的:那么为何程序中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);
}
}
}

Aroutine 发表于 2003-11-25 21:54:27

注意他们的通信机制!!!

elfxx 发表于 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
页: [1]
查看完整版本: client 和server可以调换吗?高手快帮忙