ptg10805159
Section 10.22 Signal Names and Numbers 379
should be set toSIG_IGN.Infact, the shell doesn’t explicitly ignorethis signal;init
sets the disposition of the three job-control signals (SIGTSTP,SIGTTIN,andSIGTTOU)
toSIG_IGN.This disposition is then inherited by all login shells. Only a job-control
shell should reset the disposition of these three signals toSIG_DFL.
When we type the suspend character,the process receives theSIGTSTPsignal and
the signal handler is invoked. At this point, we would do any terminal-related
processing: move the cursor to the lower-left corner,restorethe terminal mode, and so
on. Wethen send ourself the same signal,SIGTSTP,after resetting its disposition to its
default (stop the process) and unblocking the signal.We have to unblock it since we’re
currently handling that same signal, and the system blocks it automatically while it’s
being caught. At this point, the system stops the process. It is continued only when it
receives (usually from the job-control shell, in response to an interactivefgcommand) a
SIGCONTsignal. Wedon’t catchSIGCONT.Its default disposition is to continue the
stopped process; when this happens, the program continues as though it returned from
thekillfunction. When the program is continued, we reset the disposition for the
SIGTSTPsignal and do whatever terminal processing we want (we could redraw the
screen, for example).
10.22 Signal Names and Numbers
In this section, we describe how to map between signal numbers and names. Some
systems provide the array
extern char *sys_siglist[];
The array index is the signal number,giving a pointer to the character string name of
the signal.
FreeBSD 8.0, Linux 3.2.0, and Mac OS X 10.6.8 all provide this array of signal names. Solaris 10
does, too, but it uses the name_sys_siglistinstead.
To print the character string corresponding to a signal number in a portable manner,
we can use thepsignalfunction.
#include <signal.h>
void psignal(intsigno,const char *msg);
The stringmsg(which normally includes the name of the program) is output to the
standarderror,followed by a colon and a space, followed by a description of the signal,
followed by a newline. IfmsgisNULL,then only the description is written to the
standarderror.This function is similar toperror(Section 1.7).
If you have asiginfostructurefrom an alternativesigactionsignal handler,
you can print the signal information with thepsiginfofunction.
#include <signal.h>
void psiginfo(const siginfo_t *info,const char *msg);