LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-01-2006, 02:22 PM   #1
erwinfletch
LQ Newbie
 
Registered: Jan 2006
Posts: 17

Rep: Reputation: 0
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 );
}
 
Old 05-01-2006, 08:19 PM   #2
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
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).
 
  


Reply

Tags
signal handler


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SIGSEGV handler (segmentation fauld handler) myp Programming 8 03-08-2011 03:17 PM
RS232 programming (sigaction problem) lucky6969b Linux - Networking 2 04-05-2008 03:06 PM
sigaction() - how to create custom signals? rose_bud4201 Programming 15 05-24-2006 07:04 AM
Should I use signal() or sigaction()? .... grupoapunte Programming 2 06-05-2005 12:46 AM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 10:47 AM


All times are GMT -5. The time now is 03:49 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration