ps command: how does the '-q' option work?

According with the ps command, for the -q option

Through the man is indicated:

 -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.

And through ps --help a

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

But is not clear for me about the following parts:


  1. What does (quick mode) mean? – quick about what?
  2. What does With this option ps reads the necessary info only for the pids listed in the pidlist and doesn’t apply additional filtering rules mean?
  3. What does The order of pids is unsorted and preserved mean? – why is unsorted if theoretically we are defining the explicit set of pids? I mean ps -q <pid1>,<pid2>,...,<pidN>
  4. Therefore with these three first questions: When is mandatory use this -q option?
Asked By: Manuel Jordan

  1. Usually, ps retrieves information about all the processes in the system, before applying any filters. -q is quick because it disables this behaviour: with -q, ps only retrieves information for the listed pids.

  2. See above.

  3. Without -q, ps sorts its output according to its sort parameters. By default, it sorts by pid, so ps 102 101 100 will show pids 100, 101, and 102 (if they exist) in that order. -q doesn’t sort, so ps -q 102,101,100 will show pids 102, 101, and 100 in that order.

  4. It’s an option, it’s never mandatory. It’s useful if you want information on specific pids and nothing else; in such cases it can save a significant amount of time.

Answered By: Stephen Kitt
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.