![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting exit status of child in trap handler | rimon | Shell Programming and Scripting | 4 | 06-16-2008 10:05 PM |
| Runaway SIGALRM signal handler | stewartw | High Level Programming | 8 | 04-10-2008 09:13 PM |
| signal handler problems | blowtorch | High Level Programming | 4 | 08-26-2007 05:14 AM |
| signal handler for SIGCHLD | jens | High Level Programming | 3 | 07-02-2005 09:05 AM |
| shell script signal handler | jalburger | Shell Programming and Scripting | 2 | 12-04-2002 02:10 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Is it ok to use exit() inside a signal handler?
I catch SIGUSR1 in a signal handler and I try to close a file and then exit. The result is inconsistent. Sometimes the process exit and sometimes it returns to the original state before the signal handler was invoked. Perhaps exit is not legal in a handler function? T. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Exception handler
Show what your SIGUSR1 signal handler function looks like.
|
|
#3
|
|||
|
|||
|
If your signal handling function is declared in main(), in the parent, before any fork and the children don't deviate from this handling then the the entire process group will react according to the described signal handler.
|
|
#4
|
|||
|
|||
|
This is the signal handler function:
static void handle_sigusr1() { if (DebugFile!=NULL) { fwrite(DebugBuff.buff_ptr, DebugBuff.buff_len, 1, DebugFile); fprintf(DebugFile,"\n Shutting down process........\n"); fclose(DebugFile); } exit(0); } Tuvia |
|
#5
|
|||
|
|||
|
Quote:
Thanks, Tuvia |
|
#6
|
|||
|
|||
|
Declare the USR1 signal handler in both child and parent. This explains why some times the process exits and sometimes it seems that nothing has happened. Usually exit is the default disposition of most signals so putting it inside your handler is not good signal handling practice. Normally signal handlers trap a signal and when they return the process execution picks up from where it left off that is the process does not terminate.
|
|
#7
|
|||
|
|||
|
You should not call stdC library functions like fwrite in a signal handler. They are not atomic, so they may not complete in the event of multiple signals. Try write().
|
|||
| Google The UNIX and Linux Forums |