-p pidlist Select by PID. This selects the processes whose process ID numbers appear in pidlist. Identical to p and --pid. -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.
I see that
-q is considerably faster than
-p, taking at most one quarter the time to produce an identical listing.
$ time ps -fq "$$" UID PID PPID C STIME TTY TIME CMD vagrant 8115 3337 0 23:05 pts/0 00:00:00 bash real 0m0.003s user 0m0.001s sys 0m0.002s $ time ps -fp "$$" UID PID PPID C STIME TTY TIME CMD vagrant 8115 3337 0 23:05 pts/0 00:00:00 bash real 0m0.013s user 0m0.003s sys 0m0.009s $
On another system, I observed
ps -q to take less than a tenth the time of
However, I'm not using a forest-type listing, and I've only passed a single PID so the sorting isn't taking any time (and sorting should be negligible anyway for moderately short PID lists). There are no additional filtering rules in my command.
What all is
ps -p doing that
ps -q is not?