Background
Into Linux kernel mode and user mode, the kernel mode user mode performed by a system call (syscall).
Userspace library glibc package into the Linux kernel system calls GNU C Library library files (compatible with ANSI & POSIX C language standard), while providing support for other features.
Applications are not usually directly call the Linux kernel system call interface, but calls by the Linux kernel system call interface indirect glibc library package.
Semaphore mechanism
Linux on the principle of semaphore mechanism, I recommend reading "Unix Advanced Programming Environment" Chapter 10, this blog is just a brief introduction of its principles.
Semaphore is a soft interrupt, for asynchronous communication between the Linux kernel and applications.
Linux supports about 380 kinds of semaphores, each semaphore is represented by a 4-byte integer data. You can view all semaphores described by the man signals. No. 1 to 32 wherein the semaphore is inherited from Unix, 33 ~ 64 are defined in the Linux kernel semaphore.
Since the amount of signal processing functions can be defined in an application, if no custom, the glibc in the semaphore linked default handler. Applications can also block the specified semaphore.
Semaphore trigger situation, there are three:
After 1) Linux kernel detects abnormality to the application, the amount of a specific signal transmitted to the application, the application to capture the semaphore, the semaphore call handler;
2) Linux kernel and send a specific signal to the application because of internal events, notify the application for an event has occurred, such as the famous segmentation fault, an application to capture the semaphore, call the signal handler function;
3) Linux kernel detects an external event, such as Ctrl + C, Ctrl + Z, etc., transmits a specific signal to the application, the application to capture the semaphore, the semaphore call handler;
Common semaphore introduction
The Comment Action Standard Signal
────────────────────────────────────────────── ──────────────────────────
SIGABRT p1990 Core signal from the Abort ABORT (. 3) SIGABRT signal generated by the call abort () system, usually glibc library detecting the application exception, active trigger
SIGALRM p1990 Term the Timer Signal from Alarm (2)
SIGBUS P2001 Core bus error (Bad Memory access) SIGBUS means the bus access error, usually because the address is not aligned with lead, such as an odd address;
the SIGCHLD p1990 Ign child stopped or terminated SIGCHLD signal is sent to the amount of the main process when the child thread to terminate the execution
SIGCLD - Ign a synonym for SIGCHLD
SIGCONT P1990 Cont the Continue IF stopped
SIGEMT - Term Emulator Trap
a SIGFPE p1990 Core Floating-Point Exception
SIGHUP p1990 Term the Hangup Detected ON Controlling Terminal
or Death of Controlling Process
SIGILL p1990 Core Illegal Instruction SIGILL illegal command error may be the case of runaway or incompatible Code
the SIGINFO - for A synonym for a SIGPWR
SIGINT p1990 Keyboard Term Interrupt from
the SIGIO - Term the I / O now Possible (4.2BSD)
SIGIOT - Core IOT trap. A synonym for SIGABRT
SIGKILL P1990 Term Kill signal SIGKILL通常是通过kill -9 <pid>手动杀死进程时触发的信号量;
SIGLOST - Term File lock lost (unused)
SIGPIPE P1990 Term Broken pipe: write to pipe with no
readers; see pipe(7)
SIGPOLL P2001 Term Pollable event (Sys V).
Synonym for SIGIO
SIGPROF P2001 Term Profiling timer expired
SIGPWR - Term Power failure (System V)
SIGQUIT P1990 Core the Quit from Keyboard
SIGSEGV p1990 Core Invalid Memory Reference SIGSEGV means illegal memory access, usually in a stack overflow, wild pointers or a null pointer case;
SIGSTKFLT - Term Stack Fault ON Coprocessor (unused)
SIGSTOP p1990 the Stop the Stop Process
the SIGTSTP p1990 the Stop the Stop Terminal AT typed
SIGSYS P2001 of Bad System Call Core (for SVr4);
See Also Seccomp (2)
a SIGTERM p1990 Term the Termination signal
SIGTRAP P2001 Core the Trace / breakpoint Trap SIGTRAP semaphores are typically instrumented for debugging, such as gdb debugger breakpoint inserted like
SIGTTIN P1990 Stop Terminal input for background process
SIGTTOU P1990 Stop Terminal output for background process
SIGUNUSED - Core Synonymous with SIGSYS
SIGURG P2001 Ign Urgent condition on socket (4.2BSD)
SIGUSR1 P1990 Term User-defined signal 1
SIGUSR2 P1990 Term User-defined signal 2
SIGVTALRM P2001 Term Virtual alarm clock (4.2BSD)
SIGXCPU P2001 Core CPU time limit exceeded (4.2BSD);
see setrlimit(2)
SIGXFSZ P2001 Core File size limit exceeded (4.2BSD);
see setrlimit(2)
SIGWINCH - Ign Window resize signal (4.3BSD, Sun)
Advanced semaphore
About custom Linux operating signal handler function, shielding amount designation signal, the reference "System Programing: Signals"
Semaphore handler is essentially a repair or debugging mechanism when an exception occurs applications, because the amount of processing the signal is not a normal function call, so it will reuse the parent function stack, occurs if an exception handler semaphore, the system is no way to deal with, and therefore, the amount of signal processing functions must be safe and reliable.
Since the signal handler defined as the amount can not be done semaphore synchronization (to prevent deadlock), but can play gdb debugger by call fork or write log files to disk.