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

2021/11/10 7:12:39

本文主要是介绍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) {
           ......       
    }
}

 



这篇关于system execv... 拉起子进程,未处理信号导致主进程停止的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程