为什么杀掉进程后还能列出来?

为什么杀掉进程后还能列出来?

列出所有运行vlc的进程:

debian@debian:~$ ps aux |grep vl[c]
debian     14482  0.1  2.2 2882968 136428 ?      Sl   10:19   0:02 vlc -I telnet --telnet-host 192.168.31.167 --telnet-port 4212 --telnet-password admin
debian     15174  0.2  2.4 2881576 145368 ?      Ssl  10:32   0:03 vlc -d -I telnet --telnet-host 192.168.31.167 --telnet-port 4212 --telnet-password admin
debian     15641  0.3  2.4 2896668 146380 ?      SLsl 10:42   0:01 vlc -d -I telnet --telnet-host 192.168.31.167 --telnet-port 4212 --telnet-password admin

杀光他们:

debian@debian:~$ sudo kill 14482
debian@debian:~$ sudo kill 15174
debian@debian:~$ sudo kill 15641

再次列出:

debian@debian:~$ ps aux |grep vl[c]
debian     14482  0.1  2.2 2882968 136428 ?      Sl   10:19   0:02 vlc -I telnet --telnet-host 192.168.31.167 --telnet-port 4212 --telnet-password admin
debian     15174  0.2  2.4 2881576 145368 ?      Ssl  10:32   0:03 vlc -d -I telnet --telnet-host 192.168.31.167 --telnet-port 4212 --telnet-password admin
debian     15641  0.3  2.4 2896668 146380 ?      SLsl 10:42   0:01 vlc -d -I telnet --telnet-host 192.168.31.167 --telnet-port 4212 --telnet-password admin

为什么杀掉进程后还能列出来?

答案1

查看man kill

KILL(1)                         User Commands                        KILL(1)

NAME
       kill - send a signal to a process

SYNOPSIS
       kill [options] <pid> [...]

DESCRIPTION
       The  default signal for kill is TERM.  Use -l or -L to list available
       signals.  Particularly useful signals include HUP, INT,  KILL,  STOP,
       CONT,  and  0.  Alternate signals may be specified in three ways: -9,
       -SIGKILL or -KILL.  Negative PID values may be used to  choose  whole
       process  groups;  see the PGID column in ps command output.  A PID of
       -1 is special; it indicates all processes except the kill process it‐
       self and init.

最顶部是:“向进程发送信号”。这并不意味着该进程将被终止,只是它将被发送一个信号。

默认信号是SIGTERM。根据man signal.7SIGTERM是可捕获的。这意味着,程序收到停止请求,然后程序有机会对此执行某些操作。如果是数据库,也许在停止之前会保存。

如果程序不处理SIGTERM,或者选择执行除停止之外的其他操作,您将得到您所看到的行为。

您还可以尝试发送其他信号。 SIGINT(2) 与您在终端中使用 CTRL+C 时发送的内容相同。常见的一种SIGKILL(9)可能就是您想要的。 SIGKILL是少数不会传播到进程的信号之一。相反,它是向内核发出的信号,要求其终止进程。在这种情况下,进程是否被编码为handle并不重要SIGTERM,它会被内核停止而不被通知。缺点是如果它需要保存其工作,或通知同级它正在关闭,它就没有机会。用法是这样的:

$ sudo kill -9 14482
or
$ sudo kill -KILL 94471

man signal.7有更多详细信息。如果您的机器与我的机器不同,请使用您机器上的手册页作为参考。

   Standard signals
       Linux supports the standard signals listed below.  The second  column
       of  the table indicates which standard (if any) specified the signal:
       "P1990" indicates that  the  signal  is  described  in  the  original
       POSIX.1-1990 standard; "P2001" indicates that the signal was added in
       SUSv2 and POSIX.1-2001.

       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)

       The signals SIGKILL and SIGSTOP cannot be  caught,  blocked,  or  ig‐
       nored.

相关内容