Search code examples
linuxshellpstree

Why are some processes shown in pstree not shown in ps -ef?


As title, I run the above commands in sh shell of Linux, but I just cannot find the the child processes of pid 7459 by running "ps -ef | grep dummy". Can someone explain why there could be such difference between these 2 commands? They are active processes ,not LWP(thread), right? How can I display the threads,btw?

sh-3.2$ pstree -p  7459
dummy(7459)-+-{dummy}(7508)
            |-{dummy}(7528)
            |-{dummy}(7529)
            |-{dummy}(7530)
            |-{dummy}(7551)
            |-{dummy}(7552)
            |-{dummy}(7553)
            `-{dummy}(7554)
sh-3.2$ ps -ef | grep dummy
root      7459  7167  0 Aug28 ?        00:09:13 /usr/bin/dummy
erv      23720 17254  0 13:22 pts/4    00:00:00 grep dummy
sh-3.2$ 

Solution

  • As @nos has already said, pstree displays threads by default, but ps -ef does not.

    ps can show threads, you just didn't ask it to. Try this (it might depend what version you have):

    ps -eLf
    

    This is all in the man page.

    Linux threads are merely processes that share the same address space as another process. It's like a fork that didn't break away cleanly. You can read more in the clone syscall documentation.