Типы сигналов в линукс

Linux signals

Computer Hope

On Unix-like operating systems such as Linux, signals are software interrupts. They provide a way for the user (or a process) to directly communicate with a process.

Software may be programmed to respond intelligently to a wide array of signals, and certain signals cause processes to behave in a standardized, predefined way at the kernel level.

Description

Process signals were developed as part of UNIX in the 1970s. They are used on all modern Unix-like operating systems, including Linux, BSD, and macOS X.

When a signal is sent to a process, the operating system interrupts the normal flow of the process execution and delivers the notification. If the process has previously registered a way to handle that particular signal, that routine is executed, otherwise the system executes the default signal handler.

Signals can be sent with the kill command, which is named for its default signal (SIGKILL) that instructs the OS to forcefully terminate a process before doing anything else.

Signal names are commonly abbreviated without their SIG prefix, e.g., «KILL», including in the command arguments of kill.

Finding system-specific signals

Signals are defined in the system library signal.h. To view the signals used by your operating system, open a terminal and run man signal or man 7 signal.

Signals in Linux

Signal Number Description Standard
SIGHUP 1 The HUP signal is sent to a process when its controlling terminal is closed. It was originally designed to notify a serial line drop (HUP stands for «Hang Up»). In modern systems, this signal usually indicates the controlling pseudo or virtual terminal is closed. POSIX
SIGINT 2 The INT signal is sent to a process by its controlling terminal when a user wants to interrupt the process. This signal is often initiated by pressing Ctrl + C , but on some systems, the «delete» character or «break» key can be used. ANSI
SIGQUIT 3 The QUIT signal is sent to a process by its controlling terminal when the user requests that the process perform a core dump. POSIX
SIGILL 4 Illegal instruction. The ILL signal is sent to a process when it attempts to execute a malformed, unknown, or privileged instruction. ANSI
SIGTRAP 5 Trace trap. The TRAP signal is sent to a process when a condition arises that a debugger is tracing — for example, when a particular function is executed, or when a particular variable changes value. POSIX
SIGABRT,
SIGIOT
6 Abort process. ABRT is usually sent by the process itself, when it calls the abort() system call to signal an abnormal termination, but it can be sent from any process like any other signal. SIGIOT is a synonym for SIGABRT. (IOT stands for input/output trap, a signal which originated on the PDP-11.) 4.2 BSD
SIGBUS 7 The BUS signal is sent to a process when it causes a bus error, such as an incorrect memory access alignment or non-existent physical address. In Linux, this signal maps to SIGUNUSED, because memory access errors of this kind are not possible. 4.2 BSD
SIGFPE 8 Floating point exception. The FPE signal is sent to a process when it executes erroneous arithmetic operations, such as division by zero. ANSI
SIGKILL 9 Forcefully terminate a process. With STOP, this is one of two signals which cannot be intercepted, ignored, or handled by the process itself. POSIX
SIGUSR1 10 User-defined signal 1. This is one of two signals designated for custom user signal handling. POSIX
SIGSEGV 11 The SEGV signal is sent to a process when it makes an invalid virtual memory reference, or segmentation fault, i.e., when it performs a segmentation violation.
SIGUSR2 12 User-defined signal 2. This is one of two signals designated for custom user signal handling. POSIX
SIGPIPE 13 The PIPE signal is sent to a process when it attempts to write to a pipe without a process connected to the other end. POSIX
SIGALRM 14 The ALRM signal notifies a process that the time interval specified in a call to the alarm() system function has expired. POSIX
SIGTERM 15 The TERM signal is sent to a process to request its termination. Unlike the KILL signal, it can be caught and interpreted or ignored by the process. This signal allows the process to perform nice termination releasing resources and saving state if appropriate. It should be noted that SIGINT is nearly identical to SIGTERM. ANSI
SIGSTKFLT 16 Stack fault. Maps to SIGUNUSED in Linux.
SIGCHLD 17 The CHLD signal is sent to a process when a child process terminates, is interrupted, or resumes after being interrupted. One common usage of the signal is to instruct the operating system to clean up the resources used by a child process after its termination without an explicit call to the wait system call. POSIX
SIGCONT 18 Continue executing after stopped, e.g., by STOP POSIX
SIGSTOP 19 The STOP signal instructs the operating system to stop a process for later resumption. This is one of two signals, along with KILL that cannot be intercepted, ignored, or handled by the process itself. POSIX
SIGTSTP 20 The TSTP signal is sent to a process by its controlling terminal to request it to stop temporarily. It is commonly initiated by the user pressing Ctrl + Z . Unlike SIGSTOP, this process can register a signal handler for or ignore the signal. POSIX
SIGTTIN 21 The TTIN signal is sent to a process when it attempts to read from the tty while in the background. This signal can be received only by processes under job control. Daemons do not have controlling terminals and should never receive this signal. POSIX
SIGTTOU 22 TTOU signal is sent to a process when it attempts to write from the tty while in the background. The compliment to TTIN. POSIX
SIGURG 23 The URG signal is sent to a process when a socket has urgent or out-of-band data available to read. 4.2 BSD
SIGXCPU 24 The XCPU signal is sent to a process when it has used up the CPU for a duration that exceeds a certain predetermined user-settable value. The arrival of an XCPU signal provides the receiving process a chance to quickly save any intermediate results and to exit gracefully, before it is terminated by the operating system using the SIGKILL signal. 4.2 BSD
SIGXFSZ 25 The XFSZ signal is sent to a process when it grows a file larger than the maximum allowed size. 4.2 BSD
SIGVTALRM 26 Virtual alarm clock. May be sent by the alarm() system call. By default, this signal kills the process, but it’s intended for use with process-specific signal handling. 4.2 BSD
SIGPROF 27 Profiling alarm clock. Indicates expiration of a timer that measures CPU time used by the current process («user» time), and CPU time expended on behalf of the process by the system («system» time). These times can implement code profiling facilities. By default, this signal terminates the process, but it’s intended for use with process-specific signal handling. 4.2 BSD
SIGWINCH 28 Window change. The WINCH signal is sent to a process when its controlling terminal changes size, for instance if you resize it in your window manager. 4.3 BSD, Sun
SIGIO,
SIGPOLL
29 Input/output is now possible. SIGPOLL is a synonym for SIGIO, and in Linux its behavior is identical to SIGURG. 4.2 BSD
SIGPWR,
SIGLOST
30 Power failure. The PWR signal is sent to a process when the system detects a power failure. SIGLOST is a synonym for SIGPWR. System V
SIGUNUSED,
SIGSYS
31 Unused signal. This signal is provided for compatibility reasons, for example when porting software from an operating system with different or unsupported signals in Linux. In Linux, SIGSYS is a synonym for SIGUNUSED. System V r4
Читайте также:  Intel linux wireless firmware

Signals not supported by Linux

The following signals may be used by other systems, such as BSD, but are interpreted as SIGUNUSED in Linux.

SIGEMT The EMT signal is sent to a process when an emulator trap occurs. Unused in Linux.
SIGINFO The INFO signal is sent to a process when a status request is received from the controlling terminal. Unused in Linux
SIGLOST The LOST signal is sent to a process when a file lock is lost. Unused in Linux.
SIGSYS The SYS signal is sent to a process when it passes a bad argument to a system call. Unused in Linux.

Sending signals from the keyboard

Signals may be sent from the keyboard. Several standard defaults are listed below. Default key combinations for sending interrupt signals can be defined with the stty command.

Ctrl-C Send SIGINT (Interrupt). By default, this causes a process to terminate.
Ctrl-Z Send SIGTSTP (Suspend). By default, this causes a process to suspend all operation.
Ctrl-\ Send SIGQUIT (Quit). By default, this causes a process to terminate immediately and dump the core.
Ctrl-T Send SIGINFO (Info). By default, this causes the operating system to display information about the command. Not supported on all systems.

Real-time signals

Real-time signals are a set of signals with no predefined purpose, for programmers to use as they want in their software. Two signal names, SIGRTMIN and SIGRTMAX, define the minimum and maximum signal numbers of the real-time signals. For example, the programmer may use the signal number as SIGRTMIN+3 to refer to the fourth real-time signal number.

Examples: sending signals

The kill command sends signals to processes. Your shell may have a built-in version of kill, which supersedes the version installed at /bin/kill. The two versions have slightly different options, but basic functions are the same. The following examples may run using either version of kill.

Читайте также:  Linux ubuntu repository list

The process to be signaled is referred to by PID (process ID). If you’re unsure of the process ID, you can find it with the ps command, for example ps -aux.

Send the KILL signal to the process with PID 1234.

Kill three processes: PIDs 123, 456, and 789.

Send signal number 15 (TERM) to processes 1234 and 5678.

Same as the previous command.

List all available signals. Example output:

1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX

The special process ID -1 refers to all processes other than kill and the system root process. This command attempts to kill (-9) every possible process (-1) on the system. For more information, see the documentation of kill, linked below.

kill — End a process.
stty — Change terminal line settings.

Источник

Оцените статью
Adblock
detector