LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   howto know whether a function is called in signal handler (http://www.linuxquestions.org/questions/programming-9/howto-know-whether-a-function-is-called-in-signal-handler-380947/)

snowing 11-07-2005 08:47 PM

howto know whether a function is called in signal handler
 
I come across a problem today, could you please give some suggestions.
I wonder how to get to know whether a function is called in signal handler funtion or in normal function.
for example:
A() {
...............
}

sighandler() {
...............
A();
}
in A, is there any method to know whether this is in sighandler function? Thank you.

primo 11-07-2005 09:55 PM

Yes. From within the signal handler function you could turn on a global variable that you could test within A().

But be careful with races, because a test for this variable could not succeed and just a microsecond later a signal could come in. Plan in case the signal handler would call A() when you're within A(). Use sig_atomic_t to ensure that any assignment to this variable would be atomic (ie, if it takes >1 machine instructions, not to be interrupted in the middle of it)


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