previous | start | next

User Defined Signal Handlers

A process can replace the default signal handler for almost all signals (but not SIGKILL) by its own handler function.

A signal handler function can have any name, but must have return type void and have one int parameter.

Example, you might choose the name sigchld_handler for a signal handler for the SIGCHLD signal (termination of a child process). Then the declaration would be:

    void sigchld_handler(int sig);

When a signal handler executes, the parameter passed to it is the number of the signal.

A programmer can use the same signal handler function to handle several signals. In this case the handler would need to check the parameter to see which signal was sent.

On the other hand, if a signal handler function only handles one signal, it isn't necessary to bother examining the parameter since it will always be that signal number.



previous | start | next