fork - 子进程在复制父进程的信号处理方式

来源:互联网 发布:桌面软件管理软件 编辑:程序博客网 时间:2024/06/11 15:47
当一个进程调用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){         ;        }       }            }  


0 0