gtpc2m6s | C/C++ Language Support User's Guide |
This function permits a process to choose one of several ways to handle a condition sig from the raise, tpf_process_signals, or wait function.
Format
#include <signal.h> void(*signal (int sig, void(*func)(int)))(int);
Table 13. Signals Supported in the C/C++ Environment
Value | Default Handler Action | Meaning |
---|---|---|
SIGABND | 2 | Abnormal end signal. |
SIGABRT | 1 | Abnormal end (sent by the abort function). |
SIGALRM | 2 | Timeout signal, such as is started by the alarm function. |
SIGCHLD | 3 | Abnormal end, such as is initialized by the abort function. |
SIGFPE | 2 | Arithmetic exceptions that are not masked; for example, overflow, division by zero, and incorrect operation. |
SIGHUP | 2 | Hangup detected on controlling terminal or end of controlling process. |
SIGILL | 2 | Detection of an incorrect function image. |
SIGINT | 2 | Interactive attention. |
SIGKILL | 2 | Termination signal. See note. |
SIGPIPE | 2 | An attempt to write to a pipe when the pipe is not open for reading. |
SIGSEGV | 2 | Incorrect access to storage. |
SIGTERM | 2 | Termination request sent to the program. See note. |
SIGUSR1 | 2 | Intended for use by user applications. |
SIGUSR2 | 2 | Intended for use by user applications. |
SIGIOERR | 3 | Intended for input/output (I/O) error. |
The SIGKILL signal cannot be caught or ignored; therefore, it cannot be set using the signal function. If the signal function is coded to catch or ignore the SIGKILL signal, an error is returned. All signals, including the SIGKILL signal, remain pending (are not handled) by applications in the TPF system unless the sleep, tpf_process_signals, wait, or waitpid function is called. |
In Table 13 the default handler actions are:
The action taken when the interrupt signal is received depends on the value of func.
Otherwise, func points to a signal handler function.
When the signal is handled, the signal handler is reset to the default handler (the equivalent of signal(sig, SIG_DFL); is run) and func (the equivalent of (*func)(sig);) is run. The func function can end by processing a return statement or by calling the abort, exit, or longjmp function. If func processes a return statement, the program resumes at the point the signal was raised.
Normal Return
If successful, the call to signal returns the most recent value of func.
Error Return
If there is an error in the call, the signalfunction returns a value of -1 and a positive value in errno.
Programming Considerations
Examples
This example shows how to establish a signal handler.
#include <signal.h> #include <stdio.h> #include <stdlib.h> #define ONE_K 1024 void StrCln(int); void DoWork(char **, int); void ADLM(int size) { char *buffer; if (signal((SIGUSR1), StrCln) == SIG_ERR) { printf("Could not install user signal"); abort(); DoWork(&buffer, size); return; } void StrCln(int SIG_TYPE) { printf("Failed trying to malloc storage\n"); return; }
void DoWork(char **buffer, int size) { while (*buffer !=NULL) *buffer = (char *)malloc(size*ONE_K); if (*buffer == NULL) { if (raise(SIGUSR1)) { printf("Could not raise user signal"); abort(); } } return; }
Related Information