在类似 OS X 的系统上,ps(1) 的输出中,括号中列出的进程代表什么意思,如何终止它们?

在类似 OS X 的系统上,ps(1) 的输出中,括号中列出的进程代表什么意思,如何终止它们?
username@yosemite ~ % ps wwwaux | grep java
username        48111   0.0  0.0        0      0   ??  ?E   11:54AM   0:00.00 (java)
username        91673   0.0  0.0  2432772    508 s006  R+    3:19PM   0:00.00 grep java
username        90809   0.0  0.0        0      0   ??  ?E   12:47PM   0:00.00 (java)

我经常会遇到 JVM 像这样挂起的情况。(java)进程列表是什么意思?我该如何终止它们?kill -9 48111什么都不做,而且据我所知,列表会一直留在那里,直到我重新启动。

答案1

如有疑问,请参阅手册页:)

$ man ps
/parenth

When printing using the command keyword, a process that has exited and
has a parent that has not yet waited for the process (in other words,
a zombie) is listed as ``<defunct>'', and a process which is blocked
while trying to exit is listed as ``<exiting>''.  If the arguments
cannot be located (usually because it has not been set, as is the case
of system processes and/or kernel threads) the command name is printed
within square brackets.  The process can change the arguments shown
with setproctitle(3).  Otherwise, ps makes an educated guess as to the
file name and arguments given when the process was created by
examining memory or the swap area.  The method is inherently somewhat
unreliable and in any event a process is entitled to destroy this
information.  The ucomm (accounting) keyword can, however, be depended
on. If the arguments are unavailable or do not agree with the ucomm
keyword, the value for the ucomm keyword is appended to the arguments
in parentheses.

此外:

KEYWORDS
  The following is a complete list of the available keywords and their meanings.
  Several of them have aliases (keywords which are synonyms).
  ...
  ucomm      name to be used for accounting

看起来那些是僵尸进程,它不只是返回<defunct>进程名称,而是返回存储在某种会计记录中的内容。

至于终止这些进程,重新启动可能是最佳选择。因为它们丢失了原始 PPID 并成为 PPID 1(launchd)的子进程。您可以尝试向 launchd 发送 HUP 信号,但不要尝试向其发送 SIGKILL 或 SIGTERM 信号,否则您的系统会崩溃。

您可以使用 验证僵尸进程的 PPID ps -ef

笔记:存在一些僵尸进程不会造成任何影响。该进程实际上不再运行,已被终止,并且不使用任何系统资源(进程表中的条目除外)。

相关内容