首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ps ef还是ps -ef?

使用ps ef还是ps -ef?
EN

Ask Ubuntu用户
提问于 2017-08-03 08:06:53
回答 2查看 14.3K关注 0票数 12

我看到了ps efps -ef在输出方面的不同。有什么区别,这两个命令是正确的还是谁是首选?

EN

回答 2

Ask Ubuntu用户

回答已采纳

发布于 2017-08-03 08:12:41

请参阅man ps (在您的系统上,在线可以有不同的解释)。

代码语言:javascript
复制
This version of ps accepts several kinds of options:

   1   UNIX options, which may be grouped and must be preceded by a dash.
   2   BSD options, which may be grouped and must not be used with a dash.
   3   GNU long options, which are preceded by two dashes.

因此,第一个方法(ps ef)是BSD样式,手册页接着是

使用BSD样式选项将向默认显示中添加进程状态(stat=STAT),并显示命令args (args=COMMAND)而不是可执行名称。您可以使用PS_FORMAT环境变量重写此操作。使用BSD样式的选项还将更改流程选择,以包括您拥有的其他终端(TTY)上的进程;或者,这可以描述为将选择设置为筛选的所有进程的集合,以排除其他用户拥有的进程或终端上的进程。当选项在下面被描述为“相同”时,不考虑这些影响,因此-M将被认为与Z相同等等。

因此,这两个命令都是有效的,但它们显示的信息并不相同。

票数 18
EN

Ask Ubuntu用户

发布于 2017-08-03 08:14:17

man ps说:

代码语言:javascript
复制
This version of ps accepts several kinds of options:

1   UNIX options, which may be grouped and must be preceded by a
    dash.
2   BSD options, which may be grouped and must not be used with a
    dash.
3   GNU long options, which are preceded by two dashes.

因此,ef使用BSD ef选项,-ef使用Unix -e-f选项。这些不同(分别是SIMPLE PROCESS SELECTIONOUTPUT FORMAT CONTROLOUTPUT MODIFIERS部分):

代码语言:javascript
复制
   -e     Select all processes.  Identical to -A.
   -f     Do full-format listing. This option can be combined with many
          other UNIX-style options to add additional columns.  It also
          causes the command arguments to be printed.  When used with
          -L, the NLWP (number of threads) and LWP (thread ID) columns
          will be added.  See the c option, the format keyword args, and
          the format keyword comm.

   e      Show the environment after the command.

   f      ASCII art process hierarchy (forest).

显然,您不是使用ef选项选择所有进程,而是使用默认的进程列表,外加一些附加格式:

代码语言:javascript
复制
By default, ps selects all processes with the same effective user ID
(euid=EUID) as the current user and associated with the same terminal
as the invoker.  It displays the process ID (pid=PID), the terminal
associated with the process (tname=TTY), the cumulated CPU time in
[DD-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD).
Output is unsorted by default.

The use of BSD-style options will add process state (stat=STAT) to
the default display and show the command args (args=COMMAND) instead
of the executable name.  You can override this with the PS_FORMAT
environment variable. The use of BSD-style options will also change
the process selection to include processes on other terminals (TTYs)
that are owned by you; alternately, this may be described as setting
the selection to be the set of all processes filtered to exclude
processes owned by other users or not on a terminal.

你应该用哪一种?你想用输出做什么?

另外,请参阅EXAMPLES部分(它非常突出地列出了-ef,并且根本没有使用BSD e选项):

代码语言:javascript
复制
EXAMPLES

   To see every process on the system using standard syntax:
      ps -e
      ps -ef
      ps -eF
      ps -ely

   To see every process on the system using BSD syntax:
      ps ax
      ps axu

   To print a process tree:
      ps -ejH
      ps axjf
票数 20
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/942529

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档