473,769 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two question about signal handlers

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
7 1419
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2876
by: Michael Pronath | last post by:
Hi, can I make sure that Python uses only async-signal safe glibc functions in signal handlers? For example, you must not call malloc or free in signal handlers, see http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html#tag_02_04_03 The reason is, that if a signal is caught while your program is in the malloc routine, and the signal handler calls malloc or free again, then the heap will be corrupted, probably...
0
3366
by: steffen staehle | last post by:
Hi, I'm writing a server process which spawns child processes via fork This server process should keep track of the number of children stil running, do the necessary cleanup to avoid zombies, etc. In the beginning I thought I had to use the POSIX module, using SigSet SigAction, sigprocmask etc. for a rather paranoid approach. Then I've rea
1
4753
by: Ahmed Ossman | last post by:
Hi Group, I have a serious question here, I got the following error after a two warnig as following: /opt/SUNWspro/bin/CC -Dsun -Dsparc -D_SYSTYPE_SYSV -DSYSTYPE_SYSV -DMK_VENDO R_CC -xO4 -DNDEBUG -DNDEBUG -I/project/qsim/iwa/simview_ss8/mgc_home.ss5/sha red/include -I. -IIsrc -I../glue -G -Dvco_ss5 -I/usr/opt/purify -I/usr/opt/p urecov -I/usr/opt/quantify -DNON_PORTABLE -DNDBGMGR -DNDBGMGR -c Isrc/swf_falcon_stubs.cxx -o...
2
2212
by: lpw | last post by:
I have dilligently reviewed FAQ-lite Section 3.2, "How do I pass a pointer-to-member-function to a signal handler, X event callback, system call that starts a thread/task, etc." The only suggestion on how to deliver a signal to an object is to do it via a global variable and a wrapper function, a technique that is generally a Bad Idea (due to the usage of a global variable). I understand that this ng is dedicated to the discussion of...
11
2974
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
13
17720
by: vashwath | last post by:
Hi all, In my current project I am using signals for error handling. Since I cannot show full code, I have just shown important piece of code which is relevant. void sigsegenv() { printf("\n\n ********** F D S Message ***********\n\n"); printf("\n\n ********** S E G M E N T A T I O N F A U L T inside F D S ***********\n\n");
1
3024
by: Spiros Bousbouras | last post by:
In 7.20.4.4 of n1124 we read: The _Exit function causes normal program termination to occur and control to be returned to the host environment. No functions registered by the atexit function or signal handlers registered by the signal function are called. Why is there a mention of signal handlers ? I
5
6647
by: david | last post by:
I'm developing a program that runs using an asyncore loop. Right now I can adequately terminate it using Control-C, but as things get refined I need a better way to stop it. I've developed another program that executes it as a child process using popen2.Popen4(). I was attempting to use signals to stop it (using os.kill()) but I keep running into a problem where sending the signal causes an infinite loop of printing the message...
9
5835
by: thagor2008 | last post by:
Is the behaviour of throwing exceptions in a unix signal handler defined? eg: void sighandler(int sig) { ... do something throw myobj; }
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.