Stacking signals

rob hulsebos hulsebos at ehvie0.tq.ine.philips.nl
Fri Dec 15 23:11:46 AEST 1989


When I run this program on my System V.2 or V.3 box, and then
send it a SIGTERM signal, the loop in "die()" is executed until
the "sleep" terminates. From that moment on, the loop in "main()"
is executed.

This is not the behaviour I expect: the routine "die()" should
*not* exit but continue to execute. Apparently, when the SIGALRM
goes off inside "sleep", the kernel executes the signal-handler
internal to "sleep", but forgets to return to the original
signal-handling routine "die()" it was executing.

>From this I conclude that signal-handling routines can not be stacked
on a V.2 or V.3 system (it works as expected on BSD), probably because
of a setjmp/longjmp construction in "sleep". Am I correct, or is there
something wrong in V.2/V.3, or is this a bug in my system?

   #include "signal.h"

   int die();
   int flag = 1;

   main()
   {
   int i;
   signal(SIGTERM, die );

   while(1 )
      {
      sleep(1 );
      if (!flag )
         write(1, "!flag\n", 6 );    /* should not be printed */
      }
   }

   die()
   {
   flag = 0;
   while(1 )
      write(1, "signal\n", 7 );
   }

When you've compiled this program, run it in the background and then
send it a SIGTERM. A few lines of "signal" will be printed followed
be lines with "!flag".

>From this I conclude that signal-handling routines can not be stacked
on a V.2 or V.3 system (it works as expected on BSD), probably because
of a setjmp/longjmp construction in "sleep". Am I correct, or is there
something wrong in V.2/V.3, or is this a bug in my system?

-------------------------------------------------------------------------------
Rob Hulsebos == hulsebos at tq.ine.philips.nl Tel +31-40-785723, Fax +31-40-786114
Philips I&E - Where the future is being made today!



More information about the Comp.unix.wizards mailing list