#include <iostream> #include <unistd.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> #include <signal.h> using namespace std; extern char **environ; void signal_handle(int signal_no){ cout << "sign:" <<signal_no << endl; } int main(int args,char *argc[]){ pid_t pid=fork(); if(pid<0){ cout << "fork error!" <<endl; }else if(pid==0){ signal(SIGUSR1,signal_handle_kill); int count=0; while(count<10){ count++; cout << "count:" <<count <<endl; sleep(1); } kill(getppid(),SIGUSR1); }else{ signal(SIGUSR1,signal_handle); pause(); } }