当一个进程调用f o r k时,其子进程继承父进程的信号处理方式。因为子进程在开始时复制了父进程存储图像,所以信号捕捉函数的地址在子进程中是有意义的; #include <sys/types.h> #include <unistd.h> #include <signal.h> #include <iostream> using namespace std; void sig_handle(int signo){ cout << "---------------------------"<< endl; cout << getpid() << ":" <<signo; } int main(int args,char *argc[]){ signal(SIGUSR1,sig_handle); pid_t pid; pid=fork(); if(pid==0){ cout << "son self pid:"<< getpid()<< endl; pause(); cout << "continue" << endl; }else{ cout << "son process:"<< pid << endl; cout << "father process:" << getpid()<<endl; kill(pid,SIGUSR1); while(true){ ; } } } 打印----------------------------------