子进程没法退出为什么?
程序代码:
#include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <stdlib.h> #include <signal.h> #include <sys/wait.h> void fun_parent(int ); void fun_child(int ); int pid,pid_f,pid_c; int main() { while((pid = fork())<0); while(1) { if(pid == 0) { pid_c = getpid(); pid_f = getppid(); signal(SIGINT,fun_child); signal(SIGQUIT,fun_child); signal(SIGUSR1,fun_child); } else { signal(SIGINT,SIG_IGN); signal(SIGQUIT,SIG_IGN); pid_f = getpid(); pid_c = pid; signal(SIGUSR1,fun_parent); signal(SIGUSR2,fun_parent); signal(SIGTSTP,fun_parent); } } return 0; } void fun_parent(int sign) { if(sign == SIGUSR1) { printf("the bus is going!\n"); } else if(sign == SIGUSR2) { printf("stop the bus\n"); } else if(sign == SIGTSTP) { printf("the end!\n"); kill(pid_c,SIGUSR1); wait(NULL); exit(0); } } void fun_child(int sign) { if(sign == SIGINT) { kill(pid_f,SIGUSR1); } else if(sign == SIGQUIT) { kill(pid_f,SIGUSR2); } else if(sign == SIGUSR1) { printf("please get off the bus!\n"); exit(0); } }