handling signals without race conditions


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers handling signals without race conditions
# 1  
Old 01-25-2012
handling signals without race conditions

Greetings,

I am writing a small program in C on UNIX, in which I am using (POSIX reliable) signals.

1. Suppose I have a signal : SIGX, and the corresponding signal handler : sigx_handler.

It is possible to receive SIGX in my process, and, while executing sigx_handler, to receive
again SIGX and to run again sigx_handler ?

What happens then ? sigx_handler (1st run) is interrupted, then it runs sigx_handler (2nd run),
then it resumes sigx_handler (1st run) ?

Is it possible to block SIGX, while running sigx_handler, and avoiding race conditions (in the C
code) in sigx_handler ? (That is, to run sigx_handler without interrupting it.) How to code this ?
I guess this implies some atomic operations...

2. Suppose my program handles SIGX, SIGY, SIGZ, using sigx_handler, sigy_handler, sigz_handler.
How to block, without race conditions, SIGY and SIGZ signals, when I enter SIGX handler (that is,
when I run sigx_handler) ?

Thank you.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Handling Signals in System Calls

What will happen if signal comes while a system call is being executed? How it will be handled? (1 Reply)
Discussion started by: rupeshkp728
1 Replies

2. Solaris

How to create core through program at the time of crash by handling signals?

I am in process of writing a library which can make any application of my product capable of creating core in the application's log folder with a product friendly core file name programatically. In my library I am registering for certain signals e.g. SIGILL, SIGFPE, SIGBUS, SIGSEGV, SIGSYS, SIGABRT... (5 Replies)
Discussion started by: rajeev_ks
5 Replies

3. AIX

How to create core through program at the time of crash by handling signals?

I am in process of writing a library which can make any application of my product capable of creating core in the application's log folder with a product friendly core file name programatically. In my library I am registering for certain signals e.g. SIGILL, SIGFPE, SIGBUS, SIGSEGV, SIGSYS, SIGABRT... (1 Reply)
Discussion started by: rajeev_ks
1 Replies

4. Shell Programming and Scripting

Errors in if conditions with to many OR conditions

Hi ALL I have a script where in i need to check for several values in if conditons but when i execute the script it throws error such as "TOO MANY ARGUMENTS" if then msg="BM VAR Issue :: bmaRequestVAR=$bmaRequestVAR , nltBMVAR=$nltBMVAR , bmaResponseVAR=$bmaResponseVAR ,... (10 Replies)
Discussion started by: nikhil jain
10 Replies

5. Programming

handling-create new SIGNALS

Hi, i cannot find in which file and function the signals are handled by default.Can anyone help me? How can i create a 33th signal? Thanks (3 Replies)
Discussion started by: Panos
3 Replies
Login or Register to Ask a Question
signal(2)							System Calls Manual							 signal(2)

NAME
signal - Modifies signal functions SYNOPSIS
#include <signal.h> void (*signal( int sig, void (*function)(int)) (int) ); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: signal(): XPG4, XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Defines the signal. All signals are valid with the exception of SIGKILL and SIGSTOP. Specifies the address of a signal handler. DESCRIPTION
The signal function provides compatibility for older versions of the operating system whose function is a subset of the sigaction function. The signal function sets the action associated with a signal. The function parameter uses the values SIG_DFL, SIG_IGN, or it can point to an address of a signal handler. A SIG_DFL value specifies the default action that is to be taken when the signal is delivered. A value of SIG_IGN specifies that the sig- nal has no effect on the receiving process. A pointer to a function requests that the signal be caught; that is, the signal should cause the function to be called. These actions are more fully described in the <signal.h> file. NOTES
The sigaction() function provides a more comprehensive and reliable mechanism for controlling signals and is recommended instead of sig- nal() for new applications. [Tru64 UNIX] The effect of calling the signal function behavior differs depending on whether the calling program is linked with either of the special libraries, libbsd or libsys5, which supply BSD or System V signaling characteristics respectively. If neither library is used, the behavior is the same as that of the sigaction function with all the flags set to 0 (zero). If the libsys5 library is used (through compilation with the -lsys5 switch), then the specified signal is not blocked from delivery when the handler is entered, and the disposi- tion of the signal reverts to SIG_DFL when the signal is delivered. If the libbsd library or the bsd_signal() function is used, the behav- ior is the same as that of the sigaction() function with the SA_RESTART flag set. [Tru64 UNIX] When compiled in the X/Open UNIX environment, calls to the signal() function are internally renamed by prepending _E to the function name. When you are debugging a module that includes the libc version of the signal() function and for which _XOPEN_SOURCE_EXTENDED has been defined, use _Esignal to refer to the signal() call. See standards(5) for information on when the _XOPEN_SOURCE_EXTENDED macro is defined. RETURN VALUES
Upon successful completion of the signal function, the value of the previous signal action is returned. Otherwise, SIG_ERR is returned and errno is set to indicate the error. ERRORS
The signal() function sets errno to the specified values for the following conditions: The sig parameter is not a valid signal number or an attempt was made to catch a signal that cannot be caught or to ignore a signal that cannot be ignored. SEE ALSO
Commands: kill(1) Functions: acct(2), bsd_signal(2), exit(2), kill(2), pause(3), ptrace(2), setjmp(3), sigaction(2), sigblock(2), sigpause(3), sigproc- mask(2), sigstack(2), sigsuspend(2), sigvec(2), umask(2), wait(2) Files: signal(4) Standards: standards(5) signal(2)