Signal Question (yes.. i read the faq)

Signal Question (yes.. i read the faq)

Post by Jeff Murp » Fri, 02 Sep 1994 04:29:24



I have the following two programs which are (roughly) equivalent:

--- #1 -------

#include <stdio.h>
#include <signal.h>

main() {
  void sig();
  signal(SIGINT, sig);
  printf("press cnt-c\n");
  sleep(10000);

Quote:}

void sig() {
  printf("cnt-c pressed\n");

Quote:}

---- #2 ----

#include <stdio.h>
#include <signal.h>

main() {
  void sig();
  struct sigaction act;
  act.sa_handler = act;
  sigemptyset(&act.sa_mask);
  sigaction(SIGINT, &act, 0);
  printf("press cnt-c\n");
  sleep(10000);

Quote:}

void sig() {
  printf("cnt-c pressed\n");

Quote:}

------------

the problem:

if compiled under 4.1.x they each enter the sig() routine everytime
control-c is pressed.

if compiled under sol 2.3 they enter only on the first control-c and
then apparently clear the sig mask and the next control-c pressed
is not caught.

this happens for all signals.. i checked the solaris porting faq and it
didnt indicate anything odd about svr4 clearing its sig masks once the
sig is handled..

what is going wrong?

 
 
 

Signal Question (yes.. i read the faq)

Post by Walter Gr » Wed, 07 Sep 1994 21:17:04


: the problem:

: if compiled under 4.1.x they each enter the sig() routine everytime
: control-c is pressed.

: if compiled under sol 2.3 they enter only on the first control-c and
: then apparently clear the sig mask and the next control-c pressed
: is not caught.

: this happens for all signals.. i checked the solaris porting faq and it
: didnt indicate anything odd about svr4 clearing its sig masks once the
: sig is handled..

: what is going wrong?

Nothing at all. The behaviour that you experienced with Solaris is the
standard behaviour of every true System V based UNIX. I think SunOS 4.1.x
is based on the Berkeley distribution, which is different in this respect.
The typical way to handle case #1 would then be:

: --- #1 -------

: #include <stdio.h>
: #include <signal.h>

: main() {
:   void sig();
:   signal(SIGINT, sig);
:   printf("press cnt-c\n");
:   sleep(10000);
: }

: void sig() {

Quote:>>> signal(SIGINT, sig);

:   printf("cnt-c pressed\n");
: }

However, this system behaviour has also some drawbacks as described in the
ancient, pre-historic book of Maurice Bach: The Design of the UNIX
Operating System (Prentice Hall), chapter 7.2, which describes the race
condition which exists during signal handling:

It can happen that a signal is received by the process after the signal
handling procedure is reset (set to default) and before the signal(2)
routine is called again (to set handling again to sig()).

Best regards

--
Walter Graf, Siemens Nixdorf, D553, D-81730 Muenchen, Deutschland


 
 
 

1. Signal Question (yes.. i read the faq)

I have the following two programs which are (roughly) equivalent:

--- #1 -------

#include <stdio.h>
#include <signal.h>

main() {
  void sig();
  signal(SIGINT, sig);
  printf("press cnt-c\n");
  sleep(10000);

void sig() {
  printf("cnt-c pressed\n");

---- #2 ----

#include <stdio.h>
#include <signal.h>

main() {
  void sig();
  struct sigaction act;
  act.sa_handler = act;
  sigemptyset(&act.sa_mask);
  sigaction(SIGINT, &act, 0);
  printf("press cnt-c\n");
  sleep(10000);

void sig() {
  printf("cnt-c pressed\n");

------------

the problem:

if compiled under 4.1.x they each enter the sig() routine everytime
control-c is pressed.

if compiled under sol 2.3 they enter only on the first control-c and
then apparently clear the sig mask and the next control-c pressed
is not caught.

this happens for all signals.. i checked the solaris porting faq and it
didnt indicate anything odd about svr4 clearing its sig masks once the
sig is handled..

what is going wrong?

2. HELP ON DIALUP ISDN

3. User Log-on Problems (yes, I read the FAQ :)

4. HOW ABOUT LINUX

5. Solaris 2.4 memory leak (yes, I read the FAQ :')

6. HACMP Failover and IP Takeover

7. My boot floppy doesn't work (yes, I read the FAQ)

8. TSM/tcgetattr problem...

9. MacOS 9.0.4 / Linux boot problems (yes, I read the FAQ)

10. Booting issues: Using partition 3 id 0 - Yes I read the FAQ

11. GGI: yes, yes and yes

12. Svgalib Questions (and yes I've read that HOWTO _and_ I'm a newbie)

13. signal() question & recv()/read()