Current location - Training Enrollment Network - Mathematics courses - Function name of signal: signal.
Function name of signal: signal.
Header file # include

Function: Set the corresponding action of the signal.

Function prototype: void (* signal (int signum, void (* handler) (int))) (int);

Or: typedefvoid (* sig _ t) (int);

Sig_t signal (int signum, sig_t handler);

Parameter description:

The first parameter signum indicates the signal type to be processed, which can accept any signal except SIGKILL and SIGSTOP.

The second parameter handler describes the action associated with the signal and can take the following three values:

(1) There is no function address that returns a value.

This function must be declared before calling signal (), and handler is the name of this function. When a signum type signal is received, the function specified by the handler is executed. The function should be defined in the following form:

void func(int SIG);

(2) Signature

This symbol indicates that the signal is ignored. After executing the corresponding signal () call, the process will ignore the signal of sig type.

(3)SIG_DFL

This symbol indicates the default processing of signals by the recovery system.

Function description:

Signal () will set the signal processing function according to the signal number specified by the parameter signum. When the specified signal arrives, it will jump to the function execution specified by the parameter handler. When the signal processing function of a signal is executed, if the process receives the signal again, the signal will be automatically stored without interrupting the execution of the signal processing function, and the corresponding processing function will be called again until the signal processing function is executed. However, if the process receives other types of signals during the execution of the signal processing function, the execution of the function will be interrupted.

Return value: Returns the pointer of the previous signal processing function, or SIG_ERR(- 1) if there is any error.

Signals can be generated in the following situations: press CTRL+C to generate SIGINT hardware interrupts, such as division by 0, illegal memory access (SIGSEV) and so on. The Kill function can send a signal Kill command to the process. In fact, it is a wrapper interrupt of the Kill function. For example, when the alarm clock times out (SIGURG), when the reader stops, it writes data into a SIGPIPE, and so on.

/* This example installs a signal handler routine for SIGFPE.

Catch the integer overflow condition and adjust it.

Go to the AX register and return. This sample program may cause

Your computer will crash and run-time errors will occur.

It depends on the memory model used.

*/

#pragma inline

# include & ltstdio.h & gt

# include & ltsignal.h & gt

void Catcher(int sig,int type,int *reglist)

{

Printf (caught! \ n);

*(reglist+8)= 3; /* make returns AX = 3 */

}

int main(void)

{

Signal (SIGFPE, catcher);

asm mov ax,07FFFH /* AX = 32767 */

Asm inc ax /* causes overflow */

Asm into /* activation handler */

/* The handler sets AX to 3 on return. If this hadn't happened,

There will be another exception the next time you "enter"

Execute after the "dec" instruction. */

Asm dec ax /* does not overflow now */

Asm into /* Inactive */

Returns 0;

}

2 signal: signal description sigabrt is generated by calling abort function, and the process exits SIGALRM abnormally. Timer timeout set by alarm function or interval timer timeout set by setitimer function is a specific hardware exception of SIGBUS. SIGCANCEL is usually caused by memory access and is used internally by Solaris thread library. When SIGCHLD is not used to terminate or stop the SIGCHLD process, it will be sent to its parent process. By default, this signal will be ignored. When the stopped process resumes running, SIGCONT will automatically send SIGEMT and related hardware exceptions SIGFPE, such as divide by 0, floating-point overflow and stop on. SIGFREEZE Solaris is proprietary. When the terminal is dormant or suspended, it sends SIGHUP to the control process, and when the terminal is disconnected, it sends SIGILL illegal command abnormal SIGINFBSD signal. Generated by status key, usually CTRL+T. The process SIGINT sent to all foreground groups is generated by interrupt key, usually CTRL+C or DELETE. The process SIGIO asynchronous IO event SIGIOT sent to all foreground groups implements related hardware exceptions, which can't be handled and ignored for SIGABRT SIGKILL generally. The abort process SIGLWP is used internally by the Solaris thread library. SIGPIPE is sent when the reader stops writing to the pipeline. When an event is sent to a pollable device, a SIGPOLL is sent. SIGPROF Setitimer specifies the analysis interval timer. SIGPWR is related to the system. It has something to do with UPS. When SIGQUIT enters the exit key (CTRL+\), it is sent to all processes in the foreground group. SIGSEGV illegally accesses SIGSTKFLT Linux, and the stack of mathematical coprocessor SIGSTOP stops the process abnormally. Unable to handle and ignore. SIGSYS illegal system calls SIGTERM to stop the process, the kill command is sent to SIGTHAW Solaris by default, and SIGTRAP implements related hardware exceptions when recovering from Suspend. Generally, it is the debug exception SIGTSTP pause key, usually CTRL+Z, which sends SIGTTIN to all processes in the background group. SIGTTOU is sent when the process of the background group tries to read the terminal. SIGURG is sent when the process of the background group tries to write to the terminal. When out-of-band data is received. When the virtual interval timer set by the SigWaiting Solaris thread Librar times out, you can send the SIG usr 1 user-defined signal 1 SIG usr 2 user-defined signal 2 SIGVTALRM setitimer function. The Ary internal implementation of private SIGWINCH will send it to all processes of the foreground group SIGXCPU when the window size of the terminal changes. When the CPU time limit expires, the SIGXFSZ process exceeds the file size limit. SigXRES is dedicated to Solaris and will be sent when the process exceeds the resource limit.