linux第2章说明了signal函数的利用:复制代码
- Signal Standard Action Comment
- ────────────────────────────────────────────────────────────────────────
- SIGABRT P1990 Core Abort signal from abort(3)
- SIGALRM P1990 Term Timer signal from alarm(2)
- SIGBUS P2001 Core Bus error (bad memory access)
- SIGCHLD P1990 Ign Child stopped or terminated
- SIGCLD - Ign A synonym for SIGCHLD
- SIGCONT P1990 Cont Continue if stopped
- SIGEMT - Term Emulator trap
- SIGFPE P1990 Core Floating-point exception
- SIGHUP P1990 Term Hangup detected on controlling terminal
- or death of controlling process
- SIGILL P1990 Core Illegal Instruction
- SIGINFO - A synonym for SIGPWR
- SIGINT P1990 Term Interrupt from keyboard
- SIGIO - Term I/O now possible (4.2BSD)
- SIGIOT - Core IOT trap. A synonym for SIGABRT
- SIGKILL P1990 Term Kill signal
- 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 Quit from keyboard
- SIGSEGV P1990 Core Invalid memory reference
- SIGSTKFLT - Term Stack fault on coprocessor (unused)
- SIGSTOP P1990 Stop Stop process
- SIGTSTP P1990 Stop Stop typed at terminal
- SIGSYS P2001 Core Bad system call (SVr4);
- see also seccomp(2)
- SIGTERM P1990 Term Termination signal
- SIGTRAP P2001 Core Trace/breakpoint trap
- 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)
SIGNAL(2) Linux Programmer's Manual SIGNAL(2)sighandler _t 规定了传入的信号处置惩罚函数的类型,内部为信号传参,返回值为void。当程序收到SIGUSR1信号时handler就会被触发。
NAME
signal - ANSI C signal handling
SYNOPSISDESCRIPTION复制代码
- #include <signal.h>
- typedef void (*sighandler_t)(int);
- sighandler_t signal(int signum, sighandler_t handler);
signal() sets the disposition of the signal signum to handler, which is either SIG_IGN, SIG_DFL, or the address of a programmer-defined function (a "signal handler").
KILL(2) Linux Programmer's Manual KILL(2)测试程序
NAME
kill - send signal to a process
SYNOPSIS
#include
#include
int kill(pid_t pid, int sig);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
kill(): _POSIX_C_SOURCE
DESCRIPTION
The kill() system call can be used to send any signal to any process group or process.
dada@dada-virtual-machine:~/test$ ./processA测试乐成
收到user1信号
收到user1信号
收到user1信号
收到user1信号
收到user1信号
收到user1信号
...
欢迎光临 qidao123.com技术社区-IT企服评测·应用市场 (https://dis.qidao123.com/) | Powered by Discuz! X3.4 |