There have been four different implementations of signals in the history of UNIX. The Interix Software Development Kit (SDK) supports only the POSIX.1 set of signal semantics. However, the Interix SDK does support several different sets of signal-handling APIs, as follows :
American National Standards Institute (ANSI) C signals are supported by the function signal() .Though this function behaves exactly as required by the ANSI C standard, that definition leaves windows of time in which signals may be lostor mishandled. The sigaction () API allows applications to close those windows.
POSIX.1 signals are supported by the functions sigaction() , sigpending () , sigprocmask () , sigsuspend() , sigemptyset() , sigfillset() , sigaddset() , sigdelset() , and sigismember() .
BSD 4.3 signals are supported by the functions killpg() , sigsetmask() , sigblock() , and sigvec() . The signal mask for these functions is int , not sigset_t .
(Although sigpause() is provided by the Interix SDK, it is provided as the System V call, which does not behave in the same way as the BSD call.)
If a future release of the Interix SDK supports more than 32 signals, these functions will become obsolete. Therefore, rather than depend on these functions, it is better to convert code to use the POSIX.1 signal calls.
System V signals are supported with the functions sighold() , sigignore() , sigpause() , sigrelse() , and sigset() .
Table 10.7 lists the POSIX-supported signals, all of which are supported by Interix.
Signal Name | Description | Default Action/Effect | Number |
---|---|---|---|
SIGABRT | Abnormal termination | Terminate process | 6 |
SIGALRM | Time-out alarm | Terminate process | 14 |
SIGBUS | Bus error | Terminate process | 10 |
SIGCHLD | Change in status of child | Ignore | 18 |
SIGCONT | Continues stopped process | Ignore | 25 |
SIGFPE | Floating-point exception | Terminate process | 8 |
SIGHUP | Hang up | Terminate process | 1 |
SIGILL | Illegal hardware instruction | Terminate process | 4 |
SIGINT | Terminal interrupt character | Terminate process | 2 |
SIGIO | I/O completion outstanding | Ignore | 19 |
SIGKILL | Termination | Terminate process (cannot be caught or ignored) | 9 |
SIGPIPE | Write to pipe with no readers | Terminate process | 13 |
SIGPOLL | Pollable event (Sys V) - synonym of SIGIO | Ignore | 22 |
SIGPROF | Profiling timer alarm | Terminate process | 29 |
SIGQUIT | Terminal quit character | Terminate process | 3 |
SIGSEGV | Invalid memory reference | Terminate process | 11 |
SIGSTOP | Stop process | Stop process (cannot be caught or ignored) | 23 |
SIGSYS | Invalid system call | Terminate process | 12 |
SIGTERM | Software termination | Terminate process | 15 |
SIGTRAP | Trace trap | Terminate process | 5 |
SIGTSTP | Terminal stop character | Stop process | 24 |
SIGTTIN | Background read from control TTY | Stop process | 26 |
SIGTTOU | Background write to control TTY | Stop process | 27 |
SIGURG | Urgent condition on socket | Ignore | 21 |
SIGUSR1 | User -defined signal | Terminate process | 16 |
SIGUSR2 | User-defined signal | Terminate process | 17 |
SIGVTALRM | Virtual time alarm | Terminate process | 28 |
SIGXCPU | CPU time limit exceeded | Terminate process | 30 |
SIGXFSZ | File size limit exceeded | Terminate process | 31 |
Interix supports most of the signal handling functions. However, Interix doesnot support some nonstandard platform-specific implementations, such as sigfpe , signal handling for specific SIGFPE codes. Table 10.8 shows platform-specific functions not supported by Interix and Interix substitutes, if they exist.
Function Name | Description | Suggested Interix Replacement |
---|---|---|
bsd_signal | Simplified signal facilities. | See sample code in UNIX bsd_signal Code Replacement, immediately following this table. |
getcontext | Gets current user context. | No support or equivalent in Interix. |
gsignal | Software signals. | No support or equivalent in Interix. |
makecontext | Manipulates user contexts. | No support or equivalent in Interix. |
psiginfo | Software signals. | No support or equivalent in Interix. |
psignal | System signal messages. | No support or equivalent in Interix. |
setcontext | Sets current user context. | No support or equivalent in Interix. |
sig2str | Translates the signal number signum to the signal name. | Write a simple table lookup routine.(See Table 10.7.) |
sigaltstack | Sets or gets signal alternative stack context. | No support or equivalent in Interix. |
sigfpe | Handles signals for specific SIGFPE codes. | _controlfp ( ,_MCW_EM) |
siggetmask | Gets the current set of masked signals. | Use sigblock(mask) or sigsetmask(mask) with mask set to zero (0). |
siginterrupt | Allows signals to interrupt functions. | Controlled by the SA_RESTART flag passed to sigaction(). |
sigsend | Sends a signal to a process or a group of processes. | No support or equivalent in Interix. |
sigsendset | Sends a signal to a process or a group of processes. | No support or equivalent in Interix. |
sigstack | Sets and/or gets alternative signal stack context. | No support or equivalent in Interix. |
ssignal | Software signals. | No support or equivalent in Interix. |
str2sig | Translates the signal name str to a signal number. | Write a simple table lookup routine.(See Table 10.7.) |
swapcontext | Manipulates user contexts. | No support or equivalent in Interix. |
sys_siglist | System signal messages. | Implement the signals shown in Table 10.7 as a vector of signal message strings. |
Code that uses the bsd_signal() function should be implemented by using other signal functions in Interix.
The function call bsd_signal(sig, func) can be implemented as follows:
#include <signal.h> void (*bsd_signal(int sig, void (*func)(int)))(int) { struct sigaction act, oact; act.sa_handler = func; act.sa_flags = SA_RESTART; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, sig); if (sigaction(sig, &act, &oact) == -1) return(SIG_ERR); return(oact.sa_handler); }
The preceding code can support calls to bsd_signal in a migrated application; it can also be used to replace use of signal() in BSD-derived applications as long as the signal handler expected a single parameter of type int . If the handler expected any other parameter or parameters, the use of signal() must be modified to use sigaction() .