ps 命令:“-q”选项如何工作?

ps 命令:“-q”选项如何工作?

根据ps命令,对于-q选项

通过man表明:

 -q pidlist
        Select by PID (quick mode). This selects the processes whose process ID numbers appear 
        in pidlist. With this option ps reads the necessary info only for the pids listed in 
        the pidlist and doesn't apply additional filtering rules. The order of pids is 
        unsorted and preserved. No additional selection options, sorting and forest type 
        listings are allowed in this mode. Identical to q and --quick-pid.

并通过ps --help a

 -q, q, --quick-pid <PID>
                      process id (quick mode)

但我不清楚以下部分:

问题

  1. 什么是(快速模式)意思是? -快的关于什么?
  2. 什么是使用此选项 ps 仅读取 pidlist 中列出的 pid 的必要信息,并且不应用额外的过滤规则意思是?
  3. 什么是pid 的顺序未排序并保留意思是? - 为什么是未排序的如果理论上我们正在定义显式的 pid 集?我是说ps -q <pid1>,<pid2>,...,<pidN>
  4. 因此,对于这三个第一个问题:什么时候强制使用此-q选项?

答案1

  1. 通常,ps检索有关的信息全部在应用任何过滤器之前,系统中的进程。-q速度很快,因为它禁用了此行为: with -qps仅检索列出的 pid 的信息。

  2. 往上看。

  3. 如果没有-q,则ps根据其排序参数对其输出进行排序。默认情况下,它按 pid 排序,因此ps 102 101 100将按顺序显示 pid 100、101 和 102(如果存在)。-q不排序,因此ps -q 102,101,100将按顺序显示 pid 102、101 和 100。

  4. 这是一个选项,从来都不是强制性的。如果您想要有关特定 pid 的信息而不是其他信息,那么它很有用;在这种情况下,它可以节省大量时间。

相关内容