alarm以後調用sleep會這樣

#include "apue.h"
#include <setjmp.h>
#include <time.h>
static void     sig_usr1(int), sig_alrm(int);
static sigjmp_buf       jmpbuf;
static volatile sig_atomic_t    canjump;
int
main(void)
{
        if (signal(SIGUSR1, sig_usr1) == SIG_ERR)
                err_sys("signal(SIGUSR1) error");
        if (signal(SIGALRM, sig_alrm) == SIG_ERR)
                err_sys("signal(SIGALRM) error");
        pr_mask("starting main: ");             /* {Prog prmask} */
        if (sigsetjmp(jmpbuf, 1)) {
                pr_mask("ending main: ");
                exit(0);
        }
        canjump = 1;    /* now sigsetjmp() is OK */
        for ( ; ; )
                pause();
}less

static void
sig_usr1(int signo)
{
        time_t  starttime;函數

        if (canjump == 0)
                return;         /* unexpected signal, ignore */atom

        pr_mask("starting sig_usr1: ");rest

alarm(3);  ci

sleep(5);
        pr_mask("finishing sig_usr1: ");
        canjump = 0;
        siglongjmp(jmpbuf, 1);  /* jump back to main, don't return */it

}io

static void
sig_alrm(int signo)
{
        pr_mask("in sig_alrm: ");
}function

按說在sleep以後應該執行sig_alrm函數的,但是爲何沒執行呢?sso

 If a signal-catching function interrupts sleep() and examines or changes either the time a SIGALRM is scheduled to be generated, the action associated with the SIGALRM signal, or whether the SIGALRM signal is blocked from delivery, the results are unspecified.

    If a signal-catching function interrupts sleep() and calls siglongjmp() or longjmp() to restore an environment saved prior to the sleep() call, the action associated with the SIGALRM signal and the time at which a SIGALRM signal is scheduled to be generated are unspecified. It is also unspecified whether the SIGALRM signal is blocked, unless the process' signal mask is restored as part of the environment.
這是答案,唉,折騰了一夜啊im

相關文章
相關標籤/搜索