Abnormal signals in Linux

Source: Internet
Author: User

We will introduce some standard signal names and the events they represent. Each signal name is a macro representing a positive integer, but you should not try to speculate on the specific value represented by the macro, but directly use the name. This is because the value varies with different systems or versions of the same system, but the name is still standardized and unified.
These names are defined in signal. h.
Int nsig is a defined macro that describes the number of defined signals. Since the signal value is continuously allocated from 0, the nsig value is 1 larger than the maximum signal value defined in the system.

11.2.1 program error signal
The signals described below are caused by program errors. These serious errors are detected by the computer or operating system. In general, this signal indicates that your program has been seriously damaged and there is no way to continue generating wrong calculations.
Many programs need to control these signals to clean up before exiting the program. For example, disable temporary files and clear the buffer. The program can register a function handle to complete these tasks, and then let the system execute the default operation to end the process execution. Termination may be the final operation of the program that produces such errors, but there are also exceptions. For example, some programs executed in the interpretation environment must return the interpretation environment.
The default action of such signals is to terminate the execution of the program. If you define your own processing without terminating the process or blocking or ignoring the signal, your program may have extremely serious consequences. Unless this signal is not generated by an error, it is directly sent through the system by calling the kill function or the raise function.
When these signals end the process, the system will generate a kernel dump file to record the state of the program before an error exits. The file name of the kernel dump file is core, which is written to the current directory of the current process. In Linux, you can also use the environment variable corefile to set the file name that generates the kernel dump file. The purpose of generating a kernel dump file is to help you find out the cause of the Error Using the debugger later.
The following describes the names of such signals one by one:
Int sigfpe
This signal indicates a fatal arithmetic error. Although the signal is named "floating-point exception", it actually contains all arithmetic instruction errors, including Division 0 and overflow.
Int sigill
The name of this signal comes from "illegal instrution", which often means that your program needs to execute commands that cannot be decoded at all or privileged commands that you do not have permission to execute. Since the C language can only generate valid and valid commands, the sigill signal is often indicated in the following table that the executable file is damaged, or the data is being executed as code. In the latter case, a pointer is often used as a function pointer for transmission, or the data in the stack segment is broken out of the array, and the return address of the function is incorrect. Sigill can also be caused by stack overflow, or the handle of the signal response function that the system cannot execute to the system.
Int SIGSEGV
This signal is triggered when a program attempts to read or write a memory other than the memory allocated to it by the system, or when writing a memory with only the read permission. In fact, due to the limitation of the operating system detection mechanism, the detection of programs is not so timely. It is often detected only when the system is out of the range. The signal name is derived from "segmentation violation )". This signal is often caused by reference of a pointer that is not initialized or empty, or when a pointer is used to reference an array, it is out of bounds due to neglect of checking.
Int sigbus
This signal is generated because the pointer is invalid. Similar to SIGSEGV, in typical cases, it is also caused by incorrect pointer initialization. The difference between them is that SIGSEGV uses invalid pointers to reference valid memory addresses, while sigbus references invalid memory addresses. Generally, sigbus is generated because pointer variables are not correctly initialized. For example, the referenced address is an odd number when the pointer points to an 8-byte alignment variable. This signal is abbreviated as "Bus Error.
Int SIGABRT
This signal is generated by the Program Calling function abort. For more information about the usage of function abort (), see the previous sections.
Int sigiot
In Linux, it is another name of SIGABRT.
Int sigtrap
The signal is generated by the breakpoint command of the computer. The debug program uses this signal. When the program executes a breakpoint setting command, this signal is sent, and the debugging program captures this signal to gain control of the Program for debugging. Therefore, your program cannot see this signal.
Int sigemt
Simulate self-trapped signals. It is caused by the failure of the system, and must be caused by commands simulated by software. Intercept the signal and simulate the execution of the command that causes the signal in the software.
Int sigsys
Incorrect system call. That is to say, the program calls the system, but the call number passed to the system is incorrect, and the system cannot complete the call.

11.2.2 program termination signal
These signals are used to tell the program to end in some way. They have different names because they are used for a slightly different purpose, or programs want to process them in a slightly different way. Although these signals have the same consequences for the program, they all end the execution of the program, but there is still reason to process these signals. It is usually because the program wants to clear it before it ends, such as recording a certain state.
The default process (currently) ends the execution of the process.
Int sigterm
This signal is the most common signal to end the program. A process can block, control, and ignore the signal. It is a common method that politely requires a program to end. For example, the shell command kill the process by default and send the signal to end the process.
Int SIGINT
This name is short for program interrupt. It is a signal sent to the process when you enter the termination character (usually Ctrl-C) from the console.
Int sigquit
This signal is similar to Sigint. The difference is that it is generated by the user input exit character (usually Ctrl-/). In addition to process exit, a kernel dump is also generated, it is like receiving an error signal. You can think of this signal as a way to notify the program when a user discovers a program error. Some exit cleanup operations are not recommended when processing this signal, so that users can view the current status through the dumped kernel.
Int sigkill
The sigkill signal is used to terminate a process immediately. It cannot be controlled or ignored, and is always fatal or congested. This signal can only be generated directly through a specific command. Since it cannot be ignored, you should use it as the final means, and first use a less intense means, for example, Ctrl-C or sigterm. If a process does not respond to other end signals, the sigkill signal is used to always end the program. In fact, if the sigkill signal does not work, you should report a kernel error. When a process cannot be executed due to a certain reason, the system can also send the message to end the process execution.
Int sighup
The sighup signal (Hang UP) reports that the user's terminal has been disconnected from the system or used as a means of job control.

11.2.3 alarm signal
This type of signal is used to indicate that the timer is activated, and the default behavior of the signal is to end the process. Although this default behavior is usually useless, there is no other default behavior available. Therefore, programs often need to use their own functions to control the behavior of such signals.
Int sigalrm
This signal is used by a timer using the actual time or number of clocks, such as the alarm () function.
Int sigvtalrm
This function is used by a function that uses the CPU time used by the current process.
Int sigprof
This signal is used to indicate the CPU time used by the current process and the CPU time consumed by the system serving the current process. It is generally used to generate a brief summary of the Code.

11.2.4 asynchronous I/O signal
This type of signal is related to asynchronous I/O operations. You must call the fcntl () function directly to make some file descriptors generate this signal. The default action of the signal is to ignore the function of the signal.
Int sigio
The sigio signal is sent only when an open file descriptor is ready for input and output. In many systems, this signal may be sent only by the terminal and interconnectivity, but not by common files. In the GNU system, any file, as long as you indicate that it is open asynchronously, may send this signal.
Int sigurg
This signal is only used to indicate that the set of interfaces are used to receive urgent or out-of-band data. See network programming later.
Int sigpoll
The signal of System V is similar to that of sigio and is only set up for the purpose of compatibility.

11.2.5 job control signal
This group of signals is used to support job control. Generally, you can ignore these signals and use the default behavior of the system, unless you know exactly how to control the job system.
Int sigchld
When a child process ends, it sends this signal to the parent process. The default behavior of this signal is ignored. When a process creates a function handle to process the signal and a zombie process already exists, the system determines whether the signal is generated.
Int sigcld
The old name of the signal sigchld.
Int sigcont
This signal is used to make the process continue to run after the process is stopped without any other work. You cannot block the signal, but you can set a handler for the signal, which always causes the process to execute unconditionally. Most programs have no reason to control the signal, but they simply continue interrupted operations. You can use the handler of the processing function to complete some special work you need, for example, re-print some prompts, if the program is suspended because it is waiting for input.
Int sigstop
This signal stops a process and cannot be controlled, ignored, or blocked.
Int sigtstp
This is an interactive stop signal. Unlike sigstop, it can be controlled or ignored. This signal is generated when you enter the susp character (CTRL-z) in the console.
Int sigttin
When a process is executed in the background, it cannot read any input from the user's terminal. When a background process tries to read data from a user terminal, all processes receive a sigttin signal. The default operation of this signal is to stop the process, so that the background process to be input can read the required input information to the foreground.
Int sigttou
Similar to sigttin, it only occurs when the background process writes the terminal.
When a process stops, no signal is sent to it. Except for the sigkill and sigcont signals (apparently), all signals to it are marked as unfixed (pending ), and only when the process enters the execution status again can it be finally transmitted. The sigkill signal always forces the process to end and cannot be blocked, ignored, or controlled. You can ignore the sigcont signal, but it can always make the stopped process continue to run. A sigcont signal can discard all uncertain stop signals. Similarly, a stop signal can discard uncertain sigcont signals.

11.2.6 operation error signal
These signals are caused by Operation errors of processes. They do not have to be program errors, but are errors that prevent operations from being completed. The default operation of these signals is to stop the process.
Int sigpipe
If you use an MPS queue or a FIFO queue for inter-process communication, you must have your application open the MPs queue and read data before writing it to the MPs queue. If it does not start at this time, or the read pipeline process unexpectedly exits, the write operation will generate a sigpipe signal. If the sigpipe signal is blocked, controlled, or ignored, an error is returned for the write operation. The error code is epipe. For more information, see the relevant chapters.
Int siglost
This signal indicates the loss of resources. In the GNU system, a server that provides services may crash unexpectedly. Generally, it is okay to ignore this signal, because errors related to this operation can cause relevant functions to return errors.
Int sigxcpu
CPU time limit. This signal indicates that the CPU time limit for the process has been reached.
Int sigxfsz
This signal indicates that the process tries to increase the file length beyond the system's limit.

11.2.7 peripheral Signal
These signals are used for various purposes and generally do not affect the execution of processes.
Int SIGUSR1
Int sigusr2
These two signals can be used for any purpose you want and are usually used for network communication. If you use a program in a process to receive the signal, another process can send a signal to the corresponding process. The default operation for this signal is to terminate the execution of the process.
Int sigwinch
This signal is sent when the number of lines and columns on each screen of the System Terminal change. Its default operation is ignored. If it is a full screen output program, you need to control the signal and reinitialize the output based on the new lines and columns on each screen.
Int siginfo
This signal can be sent to all processes in the foreground process group through the keyboard on the console. If the process receiving the signal is a leading process, it usually prints some system information and some current information of the process. If it is another process, it will not do anything by default.

11.2.7 signal message
The standard signals we mentioned above can all be described using strings provided by a system. We use the strsignal () and psignal () functions to obtain the relevant strings.
Char * strsignal (int signum)
This function returns an allocated static string used to describe the text information related to the SIGNUM signal. You do not have permission to modify the returned string. Since this string can be rewritten in another call, if you need to use it in subsequent programs, you must save the backup of this string yourself. This function is an extension of the GNU system. Its prototype is included in the string. h header file.
Void psignal (int signum, const char * message)
This function outputs a message describing the SIGNUM signal to the standard error output. If the message passing this function is a null pointer or a Null String, this function only prints standard messages related to the signal. If you pass the message parameter to a function that is not empty, the system will first output the message string and then the relevant message. This function is declared in the signal. h file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.