Steve's 'signal_handler' collection.

Everyone should have a hobby...

Here is my collection of function prototypes for the UNIX signal_handler function, gleaned from a number of different operating systems.

Background.

When a program (running under UNIX) receives a signal from the operating system (eg because the user typed a ^C), UNIX provides a facility to let you catch that signal and pass it on to one of your functions, rather than have the operating system deal with it.

The UNIX 'signal' function lets you tell the OS which function will handle which signal. You call it like this...


  signal ( signal_name, signal_handler ) ;

The signal_handler function (that you have to provide) typically needs no parameters. The issue here is how do you write the 'signal_handler' function so that it's address can be passed to the 'signal' function.

The Collection.

These function prototypes were gleaned from a number of different operating systems on machines I've used over the years.

IRIX 4.05g


 void signal_handler() ;

IRIX 5.2


 void signal_handler( int, ... ) ;

IRIX 5.3


 void signal_handler( ... ) ;

IRIX 6.2 and 6.3


  void signal_handler( int ) ;

Micro$oft Visual C++


  extern "C" void signal_handler ( int ) ;

Linux 2.0.0


  typedef void (*__sighandler_t)(int);
  __sighandler_t signal_handler ;

This is clearly just a pathetic attempt to be different from IRIX 6.2 - but you can't really expect a bunch of enthusiastic amateurs to remain totally incompatable across four generations of operating systems. :-)

Linux 2.2.5


  typedef void (*__sighandler_t) __P ((int));
  __sighandler_t signal_handler ;

Well, you can imagine my joy on unwrapping my SuSE Linux 6.1 and finding an __P in there! The double brackets around the 'int' was just icing on the cake really.

Linux 2.2.14

The man page first teases us with:
 
  void (*signal_handler)(int)
 
...but just as you drift back nostagically to the days when you could understand this stuff, they add the immortal line:
 
    "If you're confused by the prototype at  the  top  of  this
     manpage, it may help to see it separated out thus:
 
       typedef void (*sighandler_t)(int);
       sighandler_t signal(int signum, sighandler_t handler);
 
Mmmm'K.

But not to worry, after a quick rummage in the header file, the true horror is revealed:

 
  typedef void (*__sighandler_t) __PMT ((int));
  __sighandler_t signal_handler ;
 
Yep - thought so!


If you have any other examples you can email me at: steve@sjbaker.org