系统相关
首页 > 系统相关> > system execv... 拉起子进程,未处理信号导致主进程停止

system execv... 拉起子进程,未处理信号导致主进程停止

作者:互联网

linux系统 system或者execv拉起进程时;因为与子进程信号交互未做 ,导致主进程停止;

修改:在初始化处添加代码:

static void signal_handler(int sig )
{
    
}
static void signal_u_handler(int sig )
{
    
}
static void crash_handler(int sig )
{

}
static void setup_signals()
{
    struct sigaction sa;

    sa.sa_handler = signal_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    
    signal(SIGTSTP,SIG_IGN); /* ignore tty signals */
    signal(SIGTTOU,SIG_IGN);
    signal(SIGTTIN,SIG_IGN);
    //signal(SIGINT,SIG_IGN);
    signal(SIGXCPU,SIG_IGN);
    signal(SIGXFSZ,SIG_IGN);
    signal(SIGPIPE,SIG_IGN); /* ignore pipe broken signals */
    sigaction(SIGHUP,&sa,NULL);/* catch hangup signal */
    sigaction(SIGTERM,&sa,NULL);/* catch kill signal */    

    sa.sa_handler = signal_u_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    sigaction(SIGUSR1,&sa,NULL);
    sigaction(SIGUSR2,&sa,NULL);

    sa.sa_handler = crash_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    sigaction(SIGSEGV,&sa,NULL);
    sigaction(SIGILL,&sa,NULL);
    sigaction(SIGABRT,&sa,NULL);
    sigaction(SIGFPE,&sa,NULL);
    sigaction(SIGBUS,&sa,NULL);
    sigaction(SIGPROF,&sa,NULL);
    sigaction(SIGSYS,&sa,NULL);
}

 

srs_error_t SrsVideoClipDvr::cycle()
{
    srs_error_t err = srs_success;
    
    setup_signals();
    while (!disposed) {
           ......       
    }
}

 

标签:...,signal,system,handler,进程,IGN,sa,NULL,sigaction
来源: https://www.cnblogs.com/huyupei/p/15529593.html