Linux semaphore signal 0)

Source: Internet
Author: User
Tags posix

From: http://www.dbafree.net /? P = 870

We can use kill-L to view all the semaphore interpretations, but we cannot see the signal 0 interpretations.

[root@testdb~]# kill -l 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL 5) SIGTRAP      6) SIGABRT      7) SIGBUS       

 SIGFPE 9) SIGKILL     10) SIGUSR1     11) SIGSEGV     12) SIGUSR213) SIGPIPE     14) SIGALRM     15) SIGTERM     17) SIGCHLD18) SIGCONT     19) SIGSTOP     20) SIGTSTP     21) SIGTTIN22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO30) SIGPWR      31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+136) SIGRTMIN+2  37) SIGRTMIN+3  38) SIGRTMIN+4  39) SIGRTMIN+540) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8  43) SIGRTMIN+944) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+1348) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-1352) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-956) SIGRTMAX-8  57) SIGRTMAX-7  58) SIGRTMAX-6  59) SIGRTMAX-560) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2  63) SIGRTMAX-164) SIGRTMAX

I searched online and found the explanation of signal 0 in this document, which is very good:

Http://www.linuxjournal.com/content/monitoring-processes-kill-0

"Signal 0" is kind of like a moral equivalent of "ping ".

Using "kill-0 NNN" in a shell script is a good way to tell if PID "NNN" is alive or not:

Signal 0 is just used to check process is exists or not.

In other semaphores off description, original: http://hi.baidu.com/syqust/blog/item/cd8f6c633b8a617c0d33fa35.html

Signal nature
A signal is a simulation of the interrupt mechanism at the software level. In principle, a process receives a signal and the processor receives an interrupt request. The signal is asynchronous. A process does not have to wait for the signal to arrive through any operation. In fact, the process does not know when the signal will arrive.

Signals are the only asynchronous communication mechanism in the inter-process communication mechanism. They can be seen as asynchronous notifications to notify the processes that receive signals of what happened. After POSIX real-time expansion, the signal mechanism is more powerful. In addition to the basic notification function, it can also transmit additional information.

Use kill-L to display a list of signals supported by Linux.
In the list, the number is 1 ~ The 31 signal is a traditional Unix-supported signal, which is an unreliable signal (non-real-time) numbered 32 ~ The 63 signal was expanded later, called a reliable signal (real-time signal ). The difference between unreliable and reliable signals is that the former does not support queuing and may cause signal loss, while the latter does not.

Next we will discuss the signals whose numbers are smaller than sigrtmin (the numbers below correspond to the numbers 1-31 in turn ).

1) sighup
This signal is sent at the end of the user terminal connection (normal or abnormal). Generally, when the control process of the terminal ends, it notifies all jobs in the same session, they are no longer associated with control terminals.

When you log on to Linux, the system assigns a session to the login user ). All programs running on this terminal, including foreground and background process groups, generally belong to this session. When you log out of Linux, processes in the frontend process group and in the background that are output to the terminal will receive a sighup signal. The default operation for this signal is to terminate the process. Therefore, the Process with terminal output in the frontend and backend will be aborted. However, this signal can be captured. For example, wget can capture the sighup signal and ignore it. In this way, even if you log out of Linux, wget can continue downloading.

In addition, this signal is used to notify the daemon that is out of the relationship with the terminal to re-read the configuration file.

2) SIGINT
The interrupt signal is sent when you type the intr character (usually Ctrl-C) to notify the foreground process group to terminate the process.

3) sigquit
Similar to SIGINT, but controlled by the quit character (usually Ctrl-\). A process generates a core file when it exits because it receives a sigquit exit. In this sense, it is similar to a program error signal.

4) sigill
The execution of invalid commands is usually caused by errors in the executable file, or the attempt to execute data segment. Stack Overflow may also generate this signal.

5) sigtrap
Generated by breakpoint commands or other trap commands. Used by debugger.

6) SIGABRT
The signal generated by calling the abort function.

7) sigbus
Invalid Address, including memory address alignment error. For example, you can access an integer with four characters in length, but its address is not a multiple of 4. It differs from SIGSEGV in that the latter is triggered by illegal access to valid storage addresses (for example, access does not belong to your own bucket or read-only bucket ).

Sigfpe
When a fatal arithmetic operation error occurs, it includes not only floating point operation errors, but also overflow and Division 0 and other arithmetic errors.

9) sigkill
It is used to immediately end the running of the program. This signal cannot be blocked, processed, or ignored. If the Administrator finds that a process cannot be terminated, he can try to send this signal.

10) SIGUSR1
Reserved for users

11) SIGSEGV
Try to access the memory not allocated to you, or try to write data to the memory address that has no write permission.

The signal 11 indicates that illegal memory access under certain conditions may exist in the program.

12) sigusr2
Reserved for users

13) sigpipe
Pipe rupture. This signal is usually generated during inter-process communication. For example, for two processes that use FIFO (pipeline) Communication, the read pipeline is written to the pipeline if it is not opened or unexpectedly terminated, and the write process receives the sigpipe signal. In addition, when writing a socket to two processes that communicate with a socket, the read process is terminated.

14) sigalrm
The scheduled clock signal is used to calculate the actual time or clock time. The alarm function uses this signal.

15) sigterm
The program terminate signal. Unlike sigkill, the signal can be blocked and processed. It is usually used to require the program to exit normally. The shell command kill generates this signal by default. If the process cannot be terminated, we will try sigkill.

17) sigchld
When the child process ends, the parent process receives this signal.

If the parent process does not process this signal and does not wait for the child process (wait), although the child process terminates, it still occupies a table item in the kernel table, at this time, sub-processes are called Zombie processes. In this situation, we should avoid (parent process, ignore sigchild signal, capture it, or wait, its derived child process, or the parent process is terminated first, at this time, the termination of the sub-process is automatically taken over by the INIT process ).

18) sigcont
Let a stopped process continue execution. this signal cannot be blocked. A handler can be used to allow a program to complete a specific job when it changes from the stopped state to the continue execution. for example, re-display the prompt

19) sigstop
Stop (stopped) process execution. Note the difference between it and terminate and interrupt: the process has not ended, but is paused. This signal cannot be blocked, processed, or ignored.

20) sigtstp
The process is stopped, but the signal can be processed and ignored. This signal is sent when you type the susp character (usually Ctrl-Z ).

21) sigttin
When a background job reads data from a user terminal, all processes in the job receive the sigttin signal.

22) sigttou
Similar to sigttin, but received when writing terminal (or modifying terminal mode.

23) sigurg
It is generated when "urgent" data or out-of-band data reaches the socket.

24) sigxcpu
The CPU time limit is exceeded. This limit can be read/changed by getrlimit/setrlimit.

25) sigxfsz
When a process attempts to expand a file so that it exceeds the file size resource limit.

26) sigvtalrm
The virtual clock signal is similar to sigalrm, but the CPU time occupied by the process is calculated.

27) sigprof
Similar to sigalrm/sigvtalrm, but includes the CPU time used by the process and the time when the system calls it.

28) sigwinch
Window size changed.

29) sigio
The file descriptor is ready for input/output operations.

30) sigpwr
Power failure

31) sigsys
Invalid system call.

Among the Signals listed above, signals that cannot be captured, blocked, or ignored by the program are: sigkill, sigstop
Signals that cannot be restored to the default action include: sigill and sigtrap.
By default, the signals that cause process abortion include: SIGABRT, sigbus, sigfpe, sigill, sigiot, sigquit, SIGSEGV, sigtrap, sigxcpu, sigxfsz
By default, the process exits with the following signals: sigalrm, sighup, SIGINT, sigkill, sigpipe, sigpoll, sigprof, sigsys, sigterm, SIGUSR1, sigusr2, and sigvtalrm.
By default, the signal that causes the process to stop is: sigstop, sigtstp, sigttin, sigttou
Signals ignored by default include sigchld, sigpwr, sigurg, and sigwinch.

In addition, sigio exits in svr4 and is ignored in 4.3bsd; sigcont continues when the process is suspended; otherwise, it is ignored and cannot be blocked.

When terminating a program, you cannot use sigkill if you have to. Because sigkill does not process Sub-processes, it only processes itself.

 

 

Linux supports POSIX standard and real-time signals. The following is a brief table of Linux signal. For details, see man 7 signal.

 

The default action is as follows:

Terminate a process with term

 

Signal Value Default action Meaning (reason for sending the signal)
Sighup 1 Term Terminal suspension or process death
SIGINT 2 Term Interrupt signal from keyboard
Sigquit 3 Core Exit signal from keyboard
Sigill 4 Core Invalid Command
SIGABRT 6 Core Abnormal signal from abort
Sigfpe 8 Core Floating Point exception
Sigkill 9 Term Kill
SIGSEGV 11 Core Invalid segment error (Invalid Memory Reference)
Sigpipe 13 Term MPs queue corruption: write data to an MPS queue that has no read process.
Sigalrm 14 Term Time Signal from alarm timer
Sigterm 15 Term Termination
SIGUSR1 30, 10, 16 Term User-Defined signal 1
Sigusr2 31,12, 17 Term User-Defined Signal 2
Sigchld 20, 17, 18 IGN Sub-process stop or stop
Sigcont 19,18, 25 Cont If it is stopped, continue to execute
Sigstop 17,19, 23 Stop Non-terminal stop signal
Sigtstp 18, 20, 24 Stop Stop signal from Terminal
Sigttin 21, 26 Stop Background process read Terminal
Sigttou 22, 22, 27 Stop Background Process Writing Terminal
Sigbus 10, 7, 10 Core Bus Error (Memory Access Error)
Sigpoll Term The pollable event occurs (sys V), which is synonymous with sigio.
Sigprof 27,27, 29 Term When the timer is used to calculate the distribution chart
Sigsys 12,-, 12 Core Invalid System Call (svr4)
Sigtrap 5 Core Tracking/breakpoint self-trapping
Sigurg 16,23, 21 IGN Socket emergency signal (4.2bsd)
Sigvtalrm 26, 26, 28 Term Virtual timer (4.2bsd)
Sigxcpu 24, 24, 30 Core CPU limit exceeded (4.2bsd)
Sigxfsz 25, 25, 31 Core Exceeds the file length limit (4.2bsd)
Sigiot 6 Core Iot traps, synonymous with SIGABRT
Sigemt 7,-, 7 Term
Sigstkflt -, 16 ,- Term Coprocessor stack error (not used)
Sigio 23, 29, 22 Term I/O operations can be performed on the descriptor
Sigcld -,-, 18 IGN Synonymous with sigchld
Sigpwr 29,30, 19 Term Power failure (System V)
Siginfo 29 ,-,- Synonymous with sigpwr
Siglost -,-,- Term File lock loss
Sigwinch 28, 28, 20 IGN Window Size Change (4.3bsd, Sun)
Sigunused -, 31 ,- Term Will be sigsys)

 

Note:

The values of some signals are related to the hardware structure (generally, the first value is used for the Alpha and platinum architectures, the middle value is used for the i386, PPC and sh architectures, and the third value is used for the MIPs architectures, -indicates that the value of the corresponding architecture is unknown ).

 

The blue is the POSIX.1-1990 standard signal.

Sigkill and sigstop signals cannot be hooked, blocked, or ignored.

 

Blue is the signal defined by susv2 and POSIX.1-2001.

Before the Linux 2.2 (including) kernel, the default action of sigsys, sigxcpu, sigxfsz, and sigbus (except for the iSCSI and MIPS architectures) is to terminate the process, but there is no core dump. Linux 2.4 follows POSIX.1-2001 requirements, and the default action of these signals is changed to: Terminate the process and perform core dump at the same time.

 

Orange is another common signal.

Signal 29 is siginfo/sigpwr on alpha and siglost On iSCSI.

Sigemt is not described in the POSIX.1-2001, but can still be seen in most unices, the typical default action is to terminate the process and do core dump.

Sigpwr is not described in the POSIX.1-2001, and the typical default action in some of its unices is ignored.

Sigio is not described in the POSIX.1-2001, and the typical default action in some of its unices is ignored.

 

Processes can use sigaction and signal system calls to change the default Signal Processing Method (with poor portability of signal ). Processes can select one of the following Signal Processing Methods:

1. Perform the default operation;

2. Ignore this signal;

3. Capture the signal, but use the signal handle to call the custom processing function.

 

The signal may be blocked. Each thread in the process has an independent signal mask, which indicates that the signal of the thread is blocked. The thread uses pthread_sigmask to set its signal mask. A single-threaded program can use sigprocmask to operate the signal mask. In multi-threaded programs, all threads process a specified signal by default.

 

 

Supplement:

Sig_dfl and sig_ign indicate function pointers without return values. The pointer values are 0 and 1 respectively. These two pointer values are logically impossible function address values in the program.

Sig_dfl: Default Signal Processing Program
Sig_ign: process that ignores Signals

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.