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) {
           ......       
    }
}

 

上一篇:python3 使用反射的编程思想,加强代码的扩展性


下一篇:Mysql查看连接数(连接总数、活跃数、最大并发数)