signal

作者: 滩主 | 来源:发表于2020-04-02 14:49 被阅读0次

    目前没找到怎么实现,进程处于系统调用态时ignore某信号,处于用户态模式响应该信号

    ps -ef | grep a.out | grep -v grep | awk '{print $2}' | xargs -I % kill -urg %
    
    #include <unistd.h>
    #include <stdio.h>
    #include <string.h>
    #include <signal.h>
    
    
    static void hdl (int sig, siginfo_t *siginfo, void* context)
    {
        printf("recv hdl\n");
    }
    int main()
    {
        struct sigaction act;
        memset (&act, '\0', sizeof(act));
        act.sa_sigaction = &hdl;
        // act.sa_flags = SA_ONSTACK | SA_SIGINFO |SA_RESTART;
        act.sa_flags = SA_RESTART;
        signal (SIGURG, SIG_IGN);
        if (sigaction(SIGURG, &act, NULL) < 0) {
            printf("sigaction err");
            return 1;
        }
    
        sleep(600);
        return 0;
    }
    
    #include <time.h>
    #include <stdio.h>
    #include <string.h>
    #include <signal.h>
    #include <unistd.h>
    
    static void hdl (int sig, siginfo_t *siginfo, void* context)
    {
        printf("recv hdl\n");
    }
    
    int main()
    {
        struct sigaction act;
        memset (&act, '\0', sizeof(act));
        act.sa_sigaction = &hdl;
        act.sa_flags = SA_ONSTACK | SA_SIGINFO ;
        if (sigaction(SIGUSR1, &act, NULL) < 0) {
            printf("sigaction err");
            return 1;
        }
    
        struct sigevent event;
        timer_t timer_id;
    
        event.sigev_value.sival_ptr = &timer_id;
        event.sigev_notify = SIGEV_SIGNAL;
        event.sigev_signo = SIGUSR1;
        timer_create(CLOCK_REALTIME, &event, &timer_id);
        struct itimerspec ts;
        ts.it_interval.tv_sec = 0; // the spacing time
        ts.it_interval.tv_nsec = 50000000;
        ts.it_value.tv_sec = 0;  // the delay time start
        ts.it_value.tv_nsec = 10000000;
        int ret = timer_settime(timer_id, 0, &ts, NULL);
        if (ret)
            printf("set time err:%d",ret);
    
        printf("cmd1\n");
        sleep(60);
        printf("cmd2\n");
        getchar();
        printf("cmd3\n");
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:signal

          本文链接:https://www.haomeiwen.com/subject/casxphtx.html