代码仅供参考
include#include #include #include int wait_flag; void stop(); main(){ int pid1,pid2; signal(3,stop); while((pid1=fork())== -1); if(pid1>0){ while((pid2=fork())== -1); if(pid2>0){ wait_flag=1; sleep(5); kill(pid1,16); kill(pid2,17); wait(0); wait(0); printf("n Parent process is killed!!n"); return 0; }else{ wait_flag=1; signal(17,stop); printf("n Chile process 2 is killed bu parent!!n"); return 0; } }else{ wait_flag=1; signal(16,stop); printf("n Chile process 1 is killed by parent!!n"); return 0; } } void stop(){ wait_flag=0; }



