LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   send arguments to a sigaction handler (https://www.linuxquestions.org/questions/programming-9/send-arguments-to-a-sigaction-handler-440602/)

erwinfletch 05-01-2006 01:22 PM

send arguments to a sigaction handler
 
Hi-

Is it possible to send arguments to the sigaction handler? Here is my code:

Code:


void TimerProc(int isg, siginfo_t *info, void *flag)
{
    // I want to access variables from main here with out having to make them global.  Is this possible?
    timerExpired = true; // how do I pass timerExpired to the handler?
}

int main()
{

    bool timerExpired = false;

    struct sigaction sact;
    struct itimerval value;

    memset (&sact, 0, sizeof(sact));
    sact.sa_sigaction = &TimerProc; // how do I pass timerExpired to the handler?
    sigaction (SIGVTALRM, &sact, NULL);

    value.it_interval.tv_sec = 0;
    value.it_interval.tv_usec = 15000;
    value.it_value.tv_sec = 0;
    value.it_value.tv_usec = 15000;

    result = setitimer( ITIMER_VIRTUAL, &value, NULL );
}


primo 05-01-2006 07:19 PM

Signals are asynchronous events. All three arguments to the signal handler are set by the kernel. If you want the signal handler to be aware of certain conditions, use global variables. Declare them like "volatile sig_atomic_t foobar;" so any fetch/set operation on the variable is atomic (ie, it won't be interrupted in the middle of the operation if it takes +1 instructions).


All times are GMT -5. The time now is 01:31 AM.