user3121134
user3121134

Reputation: 93

C: Need to pause a process until sigalrm

I have a problem with this code..

I need to put in wait (sigwait) a process until arrive two Signals SIGUSR1/SIGUSR2 (maybe I can use sigalrm to catch the signals?)

#include <signal.h>
#include <stdio.h>

int main()
{
    sigset_t set;
    int sig;

    sigemptyset(&set);
    sigaddset(&set, SIGUSR1);
    sigaddset(&set, SIGUSR2);
    sigprocmask(SIG_BLOCK, &set, NULL);
    sigwait(&set, &sig);
    printf("Got signal %d\n", sig);
    /*need to set Sigalrm?*/
    return 0;
}

Upvotes: 1

Views: 479

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798526

Pass select() the read end of a pipe. When you catch the signal, write to the pipe. This will cause select() to return and execution to continue.

Upvotes: 1

Related Questions