What exactly does `ps -p PID` do that `ps -q PID` does not?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












According to man ps:



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



For example:



$ 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 ps -p.



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?










share|improve this question





















  • After having looked at multiple man pages such as computing.llnl.gov/tutorials/performance_tools/man/ps.txt linuxcommand.org/lc3_man_pages/ps1.html ss64.com/bash/ps.html and docs.oracle.com/cd/E19683-01/816-0210/6m6nb7mie/index.html I fail to find a -q option.
    – K7AAY
    Dec 5 at 0:53






  • 1




    @K7AAY, interesting. I see that on RHEL 6.2, in package procps-3.2.8-21.el6, there is no such flag. But on RHEL 6.7, in the newer version of the package procps-3.2.8-33.el6, it's present as excerpted above. Looks like the man pages on the internet are fairly out of date.
    – Wildcard
    Dec 5 at 1:38














up vote
0
down vote

favorite












According to man ps:



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



For example:



$ 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 ps -p.



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?










share|improve this question





















  • After having looked at multiple man pages such as computing.llnl.gov/tutorials/performance_tools/man/ps.txt linuxcommand.org/lc3_man_pages/ps1.html ss64.com/bash/ps.html and docs.oracle.com/cd/E19683-01/816-0210/6m6nb7mie/index.html I fail to find a -q option.
    – K7AAY
    Dec 5 at 0:53






  • 1




    @K7AAY, interesting. I see that on RHEL 6.2, in package procps-3.2.8-21.el6, there is no such flag. But on RHEL 6.7, in the newer version of the package procps-3.2.8-33.el6, it's present as excerpted above. Looks like the man pages on the internet are fairly out of date.
    – Wildcard
    Dec 5 at 1:38












up vote
0
down vote

favorite









up vote
0
down vote

favorite











According to man ps:



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



For example:



$ 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 ps -p.



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?










share|improve this question













According to man ps:



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



For example:



$ 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 ps -p.



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?







performance ps documentation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 4 at 23:29









Wildcard

22.6k961164




22.6k961164











  • After having looked at multiple man pages such as computing.llnl.gov/tutorials/performance_tools/man/ps.txt linuxcommand.org/lc3_man_pages/ps1.html ss64.com/bash/ps.html and docs.oracle.com/cd/E19683-01/816-0210/6m6nb7mie/index.html I fail to find a -q option.
    – K7AAY
    Dec 5 at 0:53






  • 1




    @K7AAY, interesting. I see that on RHEL 6.2, in package procps-3.2.8-21.el6, there is no such flag. But on RHEL 6.7, in the newer version of the package procps-3.2.8-33.el6, it's present as excerpted above. Looks like the man pages on the internet are fairly out of date.
    – Wildcard
    Dec 5 at 1:38
















  • After having looked at multiple man pages such as computing.llnl.gov/tutorials/performance_tools/man/ps.txt linuxcommand.org/lc3_man_pages/ps1.html ss64.com/bash/ps.html and docs.oracle.com/cd/E19683-01/816-0210/6m6nb7mie/index.html I fail to find a -q option.
    – K7AAY
    Dec 5 at 0:53






  • 1




    @K7AAY, interesting. I see that on RHEL 6.2, in package procps-3.2.8-21.el6, there is no such flag. But on RHEL 6.7, in the newer version of the package procps-3.2.8-33.el6, it's present as excerpted above. Looks like the man pages on the internet are fairly out of date.
    – Wildcard
    Dec 5 at 1:38















After having looked at multiple man pages such as computing.llnl.gov/tutorials/performance_tools/man/ps.txt linuxcommand.org/lc3_man_pages/ps1.html ss64.com/bash/ps.html and docs.oracle.com/cd/E19683-01/816-0210/6m6nb7mie/index.html I fail to find a -q option.
– K7AAY
Dec 5 at 0:53




After having looked at multiple man pages such as computing.llnl.gov/tutorials/performance_tools/man/ps.txt linuxcommand.org/lc3_man_pages/ps1.html ss64.com/bash/ps.html and docs.oracle.com/cd/E19683-01/816-0210/6m6nb7mie/index.html I fail to find a -q option.
– K7AAY
Dec 5 at 0:53




1




1




@K7AAY, interesting. I see that on RHEL 6.2, in package procps-3.2.8-21.el6, there is no such flag. But on RHEL 6.7, in the newer version of the package procps-3.2.8-33.el6, it's present as excerpted above. Looks like the man pages on the internet are fairly out of date.
– Wildcard
Dec 5 at 1:38




@K7AAY, interesting. I see that on RHEL 6.2, in package procps-3.2.8-21.el6, there is no such flag. But on RHEL 6.7, in the newer version of the package procps-3.2.8-33.el6, it's present as excerpted above. Looks like the man pages on the internet are fairly out of date.
– Wildcard
Dec 5 at 1:38










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










What I can answer exactly is: What exactly ps -q PID does not do?



  • Sort and/or select a tree from the process list given.

From add -q/q/--quick-pid option with bolding added:




This commit introduces a new option q/-q/--quick-pid to the 'ps' command. The option does a similar job to the p/-p/--pid option (i.e. selection of PIDs listed in the comma separated list that follows the option), but the new option is optimized for speed.
In cases where users only need to specify a list of PIDs to be shown and don't need other selection options, forest type output and sorting options, the new option is recommended as it decreases the initial processing delay by avoiding reading the necessary information from all the processes running on the system and by simplifying the internal filtering logic.




The option is designed to be fast.






share|improve this answer






















  • mysterious drive-by down voter...I don’t see anything wrong with this answer at all, thanks for digging up the commit and I’ve upvoted.
    – Wildcard
    Dec 5 at 6:25










  • Yes, I removed the comment(s). Yes, a random down-voter (probably). Thanks!. @Wildcard
    – Isaac
    Dec 5 at 6:27


















up vote
2
down vote













I confirmed using strace that ps -fp PID reads information about every process on the system, and ps -fq PID only reads information about one.



This can be confirmed using the following commands:



sudo strace -o /tmp/strace.p.out ps -fp $$
sudo strace -o /tmp/strace.q.out ps -fq $$
ps -e | wc -l
grep -c '"/proc/[0-9]*"' /tmp/strace.p,q.out





share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f486029%2fwhat-exactly-does-ps-p-pid-do-that-ps-q-pid-does-not%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    What I can answer exactly is: What exactly ps -q PID does not do?



    • Sort and/or select a tree from the process list given.

    From add -q/q/--quick-pid option with bolding added:




    This commit introduces a new option q/-q/--quick-pid to the 'ps' command. The option does a similar job to the p/-p/--pid option (i.e. selection of PIDs listed in the comma separated list that follows the option), but the new option is optimized for speed.
    In cases where users only need to specify a list of PIDs to be shown and don't need other selection options, forest type output and sorting options, the new option is recommended as it decreases the initial processing delay by avoiding reading the necessary information from all the processes running on the system and by simplifying the internal filtering logic.




    The option is designed to be fast.






    share|improve this answer






















    • mysterious drive-by down voter...I don’t see anything wrong with this answer at all, thanks for digging up the commit and I’ve upvoted.
      – Wildcard
      Dec 5 at 6:25










    • Yes, I removed the comment(s). Yes, a random down-voter (probably). Thanks!. @Wildcard
      – Isaac
      Dec 5 at 6:27















    up vote
    2
    down vote



    accepted










    What I can answer exactly is: What exactly ps -q PID does not do?



    • Sort and/or select a tree from the process list given.

    From add -q/q/--quick-pid option with bolding added:




    This commit introduces a new option q/-q/--quick-pid to the 'ps' command. The option does a similar job to the p/-p/--pid option (i.e. selection of PIDs listed in the comma separated list that follows the option), but the new option is optimized for speed.
    In cases where users only need to specify a list of PIDs to be shown and don't need other selection options, forest type output and sorting options, the new option is recommended as it decreases the initial processing delay by avoiding reading the necessary information from all the processes running on the system and by simplifying the internal filtering logic.




    The option is designed to be fast.






    share|improve this answer






















    • mysterious drive-by down voter...I don’t see anything wrong with this answer at all, thanks for digging up the commit and I’ve upvoted.
      – Wildcard
      Dec 5 at 6:25










    • Yes, I removed the comment(s). Yes, a random down-voter (probably). Thanks!. @Wildcard
      – Isaac
      Dec 5 at 6:27













    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    What I can answer exactly is: What exactly ps -q PID does not do?



    • Sort and/or select a tree from the process list given.

    From add -q/q/--quick-pid option with bolding added:




    This commit introduces a new option q/-q/--quick-pid to the 'ps' command. The option does a similar job to the p/-p/--pid option (i.e. selection of PIDs listed in the comma separated list that follows the option), but the new option is optimized for speed.
    In cases where users only need to specify a list of PIDs to be shown and don't need other selection options, forest type output and sorting options, the new option is recommended as it decreases the initial processing delay by avoiding reading the necessary information from all the processes running on the system and by simplifying the internal filtering logic.




    The option is designed to be fast.






    share|improve this answer














    What I can answer exactly is: What exactly ps -q PID does not do?



    • Sort and/or select a tree from the process list given.

    From add -q/q/--quick-pid option with bolding added:




    This commit introduces a new option q/-q/--quick-pid to the 'ps' command. The option does a similar job to the p/-p/--pid option (i.e. selection of PIDs listed in the comma separated list that follows the option), but the new option is optimized for speed.
    In cases where users only need to specify a list of PIDs to be shown and don't need other selection options, forest type output and sorting options, the new option is recommended as it decreases the initial processing delay by avoiding reading the necessary information from all the processes running on the system and by simplifying the internal filtering logic.




    The option is designed to be fast.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 7 at 22:42









    Wildcard

    22.6k961164




    22.6k961164










    answered Dec 5 at 4:51









    Isaac

    10.9k11648




    10.9k11648











    • mysterious drive-by down voter...I don’t see anything wrong with this answer at all, thanks for digging up the commit and I’ve upvoted.
      – Wildcard
      Dec 5 at 6:25










    • Yes, I removed the comment(s). Yes, a random down-voter (probably). Thanks!. @Wildcard
      – Isaac
      Dec 5 at 6:27

















    • mysterious drive-by down voter...I don’t see anything wrong with this answer at all, thanks for digging up the commit and I’ve upvoted.
      – Wildcard
      Dec 5 at 6:25










    • Yes, I removed the comment(s). Yes, a random down-voter (probably). Thanks!. @Wildcard
      – Isaac
      Dec 5 at 6:27
















    mysterious drive-by down voter...I don’t see anything wrong with this answer at all, thanks for digging up the commit and I’ve upvoted.
    – Wildcard
    Dec 5 at 6:25




    mysterious drive-by down voter...I don’t see anything wrong with this answer at all, thanks for digging up the commit and I’ve upvoted.
    – Wildcard
    Dec 5 at 6:25












    Yes, I removed the comment(s). Yes, a random down-voter (probably). Thanks!. @Wildcard
    – Isaac
    Dec 5 at 6:27





    Yes, I removed the comment(s). Yes, a random down-voter (probably). Thanks!. @Wildcard
    – Isaac
    Dec 5 at 6:27













    up vote
    2
    down vote













    I confirmed using strace that ps -fp PID reads information about every process on the system, and ps -fq PID only reads information about one.



    This can be confirmed using the following commands:



    sudo strace -o /tmp/strace.p.out ps -fp $$
    sudo strace -o /tmp/strace.q.out ps -fq $$
    ps -e | wc -l
    grep -c '"/proc/[0-9]*"' /tmp/strace.p,q.out





    share|improve this answer


























      up vote
      2
      down vote













      I confirmed using strace that ps -fp PID reads information about every process on the system, and ps -fq PID only reads information about one.



      This can be confirmed using the following commands:



      sudo strace -o /tmp/strace.p.out ps -fp $$
      sudo strace -o /tmp/strace.q.out ps -fq $$
      ps -e | wc -l
      grep -c '"/proc/[0-9]*"' /tmp/strace.p,q.out





      share|improve this answer
























        up vote
        2
        down vote










        up vote
        2
        down vote









        I confirmed using strace that ps -fp PID reads information about every process on the system, and ps -fq PID only reads information about one.



        This can be confirmed using the following commands:



        sudo strace -o /tmp/strace.p.out ps -fp $$
        sudo strace -o /tmp/strace.q.out ps -fq $$
        ps -e | wc -l
        grep -c '"/proc/[0-9]*"' /tmp/strace.p,q.out





        share|improve this answer














        I confirmed using strace that ps -fp PID reads information about every process on the system, and ps -fq PID only reads information about one.



        This can be confirmed using the following commands:



        sudo strace -o /tmp/strace.p.out ps -fp $$
        sudo strace -o /tmp/strace.q.out ps -fq $$
        ps -e | wc -l
        grep -c '"/proc/[0-9]*"' /tmp/strace.p,q.out






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 5 at 13:42









        JigglyNaga

        3,613829




        3,613829










        answered Dec 5 at 5:10









        Wildcard

        22.6k961164




        22.6k961164



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f486029%2fwhat-exactly-does-ps-p-pid-do-that-ps-q-pid-does-not%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay