By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,966 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,966 IT Pros & Developers. It's quick & easy.

Two question about signal handlers

P: n/a
Hello all,

I have two questions about signal handlers. First of all, is it possible to
specify a signal handler for all non-specified signals? Since ISO C defines
only six signals but POSIX defines a lot more of them, I'd like a way to
just use a generic signal handler (which just exits with a special exit
code, for instance) for all non-standard signals, but I have no idea if this
is possible while remaining ISO C compliant.

Secondly, can anyone with a copy of the C99 standard confirm that it's safe
to call _Exit() from signal handlers which may be called asynchronously?

Thanks in advance for answering.
Nov 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Mon, 25 Jul 2005 22:50:40 -0000, "Free Bird" <@> wrote:
Hello all,

I have two questions about signal handlers. First of all, is it possible to
specify a signal handler for all non-specified signals? Since ISO C defines
only six signals but POSIX defines a lot more of them, I'd like a way to
just use a generic signal handler (which just exits with a special exit
code, for instance) for all non-standard signals, but I have no idea if this
is possible while remaining ISO C compliant.

Secondly, can anyone with a copy of the C99 standard confirm that it's safe
to call _Exit() from signal handlers which may be called asynchronously?

Yes. It's specifically permitted. It will, of course, not execute any
atexit-registered functions or other signal handlers.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 15 '05 #2

P: n/a
Alan Balmer wrote:
Secondly, can anyone with a copy of the C99 standard confirm that it's safeto call _Exit() from signal handlers which may be called asynchronously?

Yes. It's specifically permitted. It will, of course, not execute any
atexit-registered functions or other signal handlers.


Ah, thank you. I just needed to be sure of that. :)
Nov 15 '05 #3

P: n/a
Free Bird wrote:
I have two questions about signal handlers. First of all, is it possible to specify a signal handler for all non-specified signals? Since ISO C defines only six signals but POSIX defines a lot more of them, I'd like a way to
just use a generic signal handler (which just exits with a special exit
code, for instance) for all non-standard signals, but I have no idea if this is possible while remaining ISO C compliant.


I don't mean to sound impatient, but doesn't anyone have an answer to this
quesion? And yes, I know I made a mistake in the subject line (maybe that
caused you to think I had only one question ;)).

If I shouldn't have posted this reminder just yet I apologize.
Nov 15 '05 #4

P: n/a
Free Bird wrote:
First of all, is it possible to specify a signal handler for all
non-specified signals?
I doubt it.
Secondly, can anyone with a copy of the C99 standard confirm that
it's safe to call _Exit() from signal handlers which may be called
asynchronously?


Does this help?

7.14.1.1 p5:

If the signal occurs other than as the result of calling the abort
or raise function, the behavior is undefined if the signal handler
refers to any object with static storage duration other than by
assigning a value to an object declared as volatile sig_atomic_t,
or the signal handler calls any function in the standard library
other than the abort function, the _Exit function, or the signal
function with the first argument equal to the signal number
corresponding to the signal that caused the invocation of the
handler. Furthermore, if such a call to the signal function
results in a SIG_ERR return, the value of errno is indeterminate.
Nov 15 '05 #5

P: n/a
Steven Kobes wrote:
Does this help?

7.14.1.1 p5:

If the signal occurs other than as the result of calling the abort
or raise function, the behavior is undefined if the signal handler
refers to any object with static storage duration other than by
assigning a value to an object declared as volatile sig_atomic_t,
or the signal handler calls any function in the standard library
other than the abort function, the _Exit function, or the signal
function with the first argument equal to the signal number
corresponding to the signal that caused the invocation of the
handler. Furthermore, if such a call to the signal function
results in a SIG_ERR return, the value of errno is indeterminate.


Ah, so that's the exact text. Thank you!
Nov 15 '05 #6

P: n/a
On Wed, 27 Jul 2005 00:52:17 -0000, "Free Bird" <@> wrote:
Free Bird wrote:
I have two questions about signal handlers. First of all, is it possible

to
specify a signal handler for all non-specified signals? Since ISO C

defines
only six signals but POSIX defines a lot more of them, I'd like a way to
just use a generic signal handler (which just exits with a special exit
code, for instance) for all non-standard signals, but I have no idea if

this
is possible while remaining ISO C compliant.


I don't mean to sound impatient, but doesn't anyone have an answer to this
quesion? And yes, I know I made a mistake in the subject line (maybe that
caused you to think I had only one question ;)).

If I shouldn't have posted this reminder just yet I apologize.

OK, I'll take a whack at it. There is no defined method of doing this.
There's nothing that I can see that would prevent you calling signal()
for the entire range of integers supported by the implementation, then
resetting the ones you want to be different, but I wouldn't recommend
it.

More sensibly, you could restrict to the range of actual signal values
for the implementation, but of course it wouldn't be portable.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 15 '05 #7

P: n/a
Alan Balmer wrote:
OK, I'll take a whack at it. There is no defined method of doing this.
There's nothing that I can see that would prevent you calling signal()
for the entire range of integers supported by the implementation, then
resetting the ones you want to be different, but I wouldn't recommend
it. Yes, that's one of the ideas I came up with, but I quickly rejected it. I
mean, I don't even want to think about how long this would take on a system
with 64-bit ints... I suppose I could call signal() for all values from 0 to
32767 and be reasonably certain I have covered all signals, but I was hoping
there would be a better way.
More sensibly, you could restrict to the range of actual signal values
for the implementation, but of course it wouldn't be portable.

Indeed.

Well, it seems there is indeed no way to do this in ISO C. That's
unfortunate, but I suppose I'll just have to live with it.
Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.