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:
Questions
- What does (quick mode) mean? – quick about what?
- 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?
- 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>
- Therefore with these three first questions: When is mandatory use this
-q
option?
-
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. -
See above.
-
Without
-q
,ps
sorts its output according to its sort parameters. By default, it sorts by pid, sops 102 101 100
will show pids 100, 101, and 102 (if they exist) in that order.-q
doesn’t sort, sops -q 102,101,100
will show pids 102, 101, and 100 in that order. -
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.