我最近开始使用htop
,并且我需要终止进程,但是当按下F9该进程时,它会给我这个选项列表,我只是选择了默认选择的选项,但我不知道它实际上是做什么的,虽然它似乎有效:
所以我真正的问题是,这些不同的选项是什么,哪一个最适合用来终止进程?
答案1
第一次尝试
SIGTERM 15 Term Termination signal
如果这不起作用
SIGKILL 9 Term Kill signal
从man 7 signal
First the signals described in the original POSIX.1-1990 standard.
Signal Value Action Comment
──────────────────────────────────────────────────────────────────────
SIGHUP 1 Term Hangup detected on controlling terminal
or death of controlling process
SIGINT 2 Term Interrupt from keyboard
SIGQUIT 3 Core Quit from keyboard
SIGILL 4 Core Illegal Instruction
SIGABRT 6 Core Abort signal from abort(3)
SIGFPE 8 Core Floating point exception
SIGKILL 9 Term Kill signal
SIGSEGV 11 Core Invalid memory reference
SIGPIPE 13 Term Broken pipe: write to pipe with no
readers
SIGALRM 14 Term Timer signal from alarm(2)
SIGTERM 15 Term Termination signal
SIGUSR1 30,10,16 Term User-defined signal 1
SIGUSR2 31,12,17 Term User-defined signal 2
SIGCHLD 20,17,18 Ign Child stopped or terminated
SIGCONT 19,18,25 Cont Continue if stopped
SIGSTOP 17,19,23 Stop Stop process
SIGTSTP 18,20,24 Stop Stop typed at terminal
SIGTTIN 21,21,26 Stop Terminal input for background process
SIGTTOU 22,22,27 Stop Terminal output for background process
The signals SIGKILL and SIGSTOP cannot be caught, blocked, or
ignored.
Next the signals not in the POSIX.1-1990 standard but described in
SUSv2 and POSIX.1-2001.
Signal Value Action Comment
────────────────────────────────────────────────────────────────────
SIGBUS 10,7,10 Core Bus error (bad memory access)
SIGPOLL Term Pollable event (Sys V).
Synonym for SIGIO
SIGPROF 27,27,29 Term Profiling timer expired
SIGSYS 12,31,12 Core Bad argument to routine (SVr4)
SIGTRAP 5 Core Trace/breakpoint trap
SIGURG 16,23,21 Ign Urgent condition on socket (4.2BSD)
SIGVTALRM 26,26,28 Term Virtual alarm clock (4.2BSD)
SIGXCPU 24,24,30 Core CPU time limit exceeded (4.2BSD)
SIGXFSZ 25,25,31 Core File size limit exceeded (4.2BSD)
答案2
这些是一般的过程信号,而不仅仅是相关的htop
,您可以使用命令列出所有信号
kill -l
例如来源:
-1 或 -HUP - 此参数使 kill 向进程发送“挂断”信号。这可能起源于调制解调器/拨号时代。进程必须经过编程才能真正监听此进程并对其执行某些操作。大多数守护进程都经过编程以在收到此类信号时重新读取其配置。无论如何;这很可能是最安全的 kill 信号,它不会阻碍任何事情。
-2 或 -SIGINT - 这与启动某个程序并在执行期间按 CTRL+C 相同。大多数程序将停止,您可能会丢失数据。
-9 或 -KILL - 内核将释放进程而不通知进程。像这样的不彻底终止可能会导致数据丢失。这是“最难”、“最粗暴”和最不安全的终止信号,只应用于停止似乎无法停止的事情。
-15 或 -TERM - 告诉进程停止正在执行的任何操作并自行结束。当您未指定任何信号时,将使用此信号。执行起来应该相当安全,但最好以“-1”或“-HUP”开头。
文件中的列表signal.h
:
+--------------------+------------------+
* | POSIX signal | default action |
* +--------------------+------------------+
* | SIGHUP | terminate |
* | SIGINT | terminate |
* | SIGQUIT | coredump |
* | SIGILL | coredump |
* | SIGTRAP | coredump |
* | SIGABRT/SIGIOT | coredump |
* | SIGBUS | coredump |
* | SIGFPE | coredump |
* | SIGKILL | terminate(+) |
* | SIGUSR1 | terminate |
* | SIGSEGV | coredump |
* | SIGUSR2 | terminate |
* | SIGPIPE | terminate |
* | SIGALRM | terminate |
* | SIGTERM | terminate |
* | SIGCHLD | ignore |
* | SIGCONT | ignore(*) |
* | SIGSTOP | stop(*)(+) |
* | SIGTSTP | stop(*) |
* | SIGTTIN | stop(*) |
* | SIGTTOU | stop(*) |
* | SIGURG | ignore |
* | SIGXCPU | coredump |
* | SIGXFSZ | coredump |
* | SIGVTALRM | terminate |
* | SIGPROF | terminate |
* | SIGPOLL/SIGIO | terminate |
* | SIGSYS/SIGUNUSED | coredump |
* | SIGSTKFLT | terminate |
* | SIGWINCH | ignore |
* | SIGPWR | terminate |
* | SIGRTMIN-SIGRTMAX | terminate |
* +--------------------+------------------+
* | non-POSIX signal | default action |
* +--------------------+------------------+
* | SIGEMT | coredump |
* +--------------------+------------------+
进一步阅读:
man signal
,,,,man 2 signal
man 7 signal
man kill
- http://man7.org/linux/man-pages/man7/signal.7.html
- http://lasr.cs.ucla.edu/vahab/resources/signals.html
- http://www.linuxprogrammingblog.com/all-about-linux-signals