|
一个消息的创建程序是这样的:那么为何程序中server在前,而client 在后;
如果在输程序中将二者交换时,为何结果如此奇怪???
交替出现是为什么?
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
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,&exitpid,0);
printf("parent process is killed \n");
exit(0);
}
}
} |
|