Linux信号类型

1、信号种类
root@yjc:~/apue/signal# kill -l
 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

总计64个信号类型,在/usr/include/x86_64-linux-gnu/bits/signum-generic.h中有对其进行解释。

root@yjc:/usr/include/x86_64-linux-gnu/bits# cat signum-generic.h 
/* Signal number constants.  Generic template.
   Copyright (C) 1991-2018 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#ifndef _BITS_SIGNUM_GENERIC_H
#define _BITS_SIGNUM_GENERIC_H 1

#ifndef _SIGNAL_H
#error "Never include <bits/signum-generic.h> directly; use <signal.h> instead."
#endif

/* Fake signal functions.  */

#define SIG_ERR  ((__sighandler_t) -1)  /* Error return.  */
#define SIG_DFL  ((__sighandler_t)  0)  /* Default action.  */
#define SIG_IGN  ((__sighandler_t)  1)  /* Ignore signal.  */

#ifdef __USE_XOPEN
# define SIG_HOLD ((__sighandler_t) 2)  /* Add signal to hold mask.  */
#endif

/* We define here all the signal names listed in POSIX (1003.1-2008);
   as of 1003.1-2013, no additional signals have been added by POSIX.
   We also define here signal names that historically exist in every
   real-world POSIX variant (e.g. SIGWINCH).

   Signals in the 1-15 range are defined with their historical numbers.
   For other signals, we use the BSD numbers.
   There are two unallocated signal numbers in the 1-31 range: 7 and 29.
   Signal number 0 is reserved for use as kill(pid, 0), to test whether
   a process exists without sending it a signal.  */

/* ISO C99 signals.  */
#define SIGINT          2       /* Interactive attention signal.  */
#define SIGILL          4       /* Illegal instruction.  */
#define SIGABRT         6       /* Abnormal termination.  */
#define SIGFPE          8       /* Erroneous arithmetic operation.  */
#define SIGSEGV         11      /* Invalid access to storage.  */
#define SIGTERM         15      /* Termination request.  */

/* Historical signals specified by POSIX. */
#define SIGHUP          1       /* Hangup.  */
#define SIGQUIT         3       /* Quit.  */
#define SIGTRAP         5       /* Trace/breakpoint trap.  */
#define SIGKILL         9       /* Killed.  */
#define SIGBUS          10      /* Bus error.  */
#define SIGSYS          12      /* Bad system call.  */
#define SIGPIPE         13      /* Broken pipe.  */
#define SIGALRM         14      /* Alarm clock.  */

/* New(er) POSIX signals (1003.1-2008, 1003.1-2013).  */
#define SIGURG          16      /* Urgent data is available at a socket.  */
#define SIGSTOP         17      /* Stop, unblockable.  */
#define SIGTSTP         18      /* Keyboard stop.  */
#define SIGCONT         19      /* Continue.  */
#define SIGCHLD         20      /* Child terminated or stopped.  */
#define SIGTTIN         21      /* Background read from control terminal.  */
#define SIGTTOU         22      /* Background write to control terminal.  */
#define SIGPOLL         23      /* Pollable event occurred (System V).  */
#define SIGXCPU         24      /* CPU time limit exceeded.  */
#define SIGXFSZ         25      /* File size limit exceeded.  */
#define SIGVTALRM       26      /* Virtual timer expired.  */
#define SIGPROF         27      /* Profiling timer expired.  */
#define SIGUSR1         30      /* User-defined signal 1.  */
#define SIGUSR2         31      /* User-defined signal 2.  */

/* Nonstandard signals found in all modern POSIX systems
   (including both BSD and Linux).  */
#define SIGWINCH        28      /* Window size change (4.3 BSD, Sun).  */

/* Archaic names for compatibility.  */
#define SIGIO           SIGPOLL /* I/O now possible (4.2 BSD).  */
#define SIGIOT          SIGABRT /* IOT instruction, abort() on a PDP-11.  */
#define SIGCLD          SIGCHLD /* Old System V name */

/* Not all systems support real-time signals.  bits/signum.h indicates
   that they are supported by overriding __SIGRTMAX to a value greater
   than __SIGRTMIN.  These constants give the kernel-level hard limits,
   but some real-time signals may be used internally by glibc.  Do not
   use these constants in application code; use SIGRTMIN and SIGRTMAX
   (defined in signal.h) instead.  */
#define __SIGRTMIN      32
#define __SIGRTMAX      __SIGRTMIN

/* Biggest signal number + 1 (including real-time signals).  */
#define _NSIG           (__SIGRTMAX + 1)

#endif /* bits/signum-generic.h.  */

#define SIG_ERR ((__sighandler_t) -1) /* Error return. /
#define SIG_DFL ((__sighandler_t) 0) /
Default action. /
#define SIG_IGN ((__sighandler_t) 1) /
Ignore signal. */

当信号发生时,我们可以用信号处理函数捕捉该信号,当信号处理函数

       = SIG_ERR,表示返回错误
       
       = SIG_IGN,表示我们忽略该信号,系统中大多数信号都是使用该处理方式进行处理的,但是,SIGKILL,SIGSTOP信号不能被忽略。

       = SIG_DFL,表示执行系统默认动作。
    定义我们自己的信号处理函数,捕捉信号。
/* Signals.  */
#define SIGHUP          1       /* Hangup (POSIX).  终端连接断开信号*/
#define SIGINT          2       /* Interrupt (ANSI).  中断信号,终端中输入ctrl+c,可中断前台进程*/
#define SIGQUIT         3       /* Quit (POSIX).   退出信号,终端中输入ctrl+\,可退出前台进程,同时产生core文件*/
#define SIGILL          4       /* Illegal instruction (ANSI). 非法指令信号,4.3BSD的abort函数产生该信号 */
#define SIGTRAP         5       /* Trace trap (POSIX).  调试信号,当在程序中设置断点后,该信号使得调试程序获得控制权*/
#define SIGABRT         6       /* Abort (ANSI). 程序异常终止信号,abort函数产生该信号 */
#define SIGIOT          6       /* IOT trap (4.2 BSD).  功能同SIGABRT*/
#define SIGBUS          7       /* BUS error (4.2 BSD).  程序访问不存在的内存区域时,产生该信号*/
#define SIGFPE          8       /* Floating-point exception (ANSI).  算术异常,如除以0*/
#define SIGKILL         9       /* Kill, unblockable (POSIX).  不能被忽略,非阻塞,可杀死任意一个运行中的进程*/
#define SIGUSR1         10      /* User-defined signal 1 (POSIX).  用户自定义1*/
#define SIGSEGV         11      /* Segmentation violation (ANSI). 当程序访问没有访问权限的内存区域,或者访问非可读的内存区域时,产生该信号,如数组越界 */
#define SIGUSR2         12      /* User-defined signal 2 (POSIX). 用户自定义2 */
#define SIGPIPE         13      /* Broken pipe (POSIX). 当管道读端已关闭,继续往管道中写,产生该信号 */
#define SIGALRM         14      /* Alarm clock (POSIX). alarm函数超时时产生该信号,默认动作是程序终止 */
#define SIGTERM         15      /* Termination (ANSI).  终止程序信号,命令kill默认使用该参数*/
#define SIGSTKFLT       16      /* Stack fault.  */
#define SIGCLD          SIGCHLD /* Same as SIGCHLD (System V).  */
#define SIGCHLD         17      /* Child status has changed (POSIX).  子进程终止或停止时,产生该信号,默认被忽略*/
#define SIGCONT         18      /* Continue (POSIX).  */
#define SIGSTOP         19      /* Stop, unblockable (POSIX).  停止一个作业控制进程*/
#define SIGTSTP         20      /* Keyboard stop (POSIX).  ctrl+z产生该信号,改信号使得前台进程挂起*/
#define SIGTTIN         21      /* Background read from tty (POSIX).  */
#define SIGTTOU         22      /* Background write to tty (POSIX).  */
#define SIGURG          23      /* Urgent condition on socket (4.2 BSD).  */
#define SIGXCPU         24      /* CPU limit exceeded (4.2 BSD).  进程超过了CPU软限制产生该信号*/
#define SIGXFSZ         25      /* File size limit exceeded (4.2 BSD).  进程超过了文件大小软限制产生该信号*/
#define SIGVTALRM       26      /* Virtual alarm clock (4.2 BSD).  */
#define SIGPROF         27      /* Profiling alarm clock (4.2 BSD).  */
#define SIGWINCH        28      /* Window size change (4.3 BSD, Sun).  */
#define SIGPOLL         SIGIO   /* Pollable event occurred (System V).  */
#define SIGIO           29      /* I/O now possible (4.2 BSD).  */
#define SIGPWR          30      /* Power failure restart (System V).  */
#define SIGSYS          31      /* Bad system call.  */
#define SIGUNUSED       31

#define _NSIG           65      /* Biggest signal number + 1
                                   (including real-time signals).  */

#define SIGRTMIN        (__libc_current_sigrtmin ())
#define SIGRTMAX        (__libc_current_sigrtmax ())
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐