AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 942529
Accepted
Niklas Rosencrantz
Niklas Rosencrantz
Asked: 2017-08-04 00:06:53 +0800 CST2017-08-04 00:06:53 +0800 CST 2017-08-04 00:06:53 +0800 CST

ps ef 或 ps -ef 使用哪个?

  • 772

ps ef我看到和之间的输出存在差异ps -ef。那有什么区别,两个命令都是正确的还是首选的?

ps
  • 2 2 个回答
  • 13982 Views

2 个回答

  • Voted
  1. muru
    2017-08-04T00:14:17+08:002017-08-04T00:14:17+08:00

    man ps说:

    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使用 BSDe和f选项,并-ef使用 Unix-e和-f选项。这些是不同的(部分SIMPLE PROCESS SELECTION和OUTPUT FORMAT CONTROL分别OUTPUT MODIFIERS):

       -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选项选择所有进程,而是使用默认的进程列表,以及一些额外的格式:

    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相当突出的内容,并且根本不使用 BSDe选项):

    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
  2. Best Answer
    Rinzwind
    2017-08-04T00:12:41+08:002017-08-04T00:12:41+08:00

    看man ps(你系统上的那个,网上可以有不同的解释)。

    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) 上的进程;或者,这可以描述为将选择设置为所有进程的集合,这些进程被过滤以排除其他用户拥有或不在终端上的进程。These effects are not considered when options are described as being "identical" below, so -M will be considered identical to Z and so on.

    所以两者都是有效的命令,但它们没有显示相同的信息。

    • 18

相关问题

  • 如何防止ps截断进程名

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve