10

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$ 
Zii
  • 359
  • 4
  • 10
  • 2
    This is covered in the documentation(man page) for pstree. " Child threads of a process are found under the parent process and are shown with the process name in curly braces", and similarly the man page for ps tells how to display threads. – nos Aug 29 '14 at 11:33

1 Answers1

11

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.

ams
  • 24,923
  • 4
  • 54
  • 75
  • 1
    Thanks, @nos and ams. I think your answers are correct! This is the first time I raise a question here and I am glad answers come so quickly. I will refer to the man page you mentioned carefully. – Zii Aug 30 '14 at 12:57
  • 1
    Welcome to stack exchange. Your next step is to accept the answer. – ams Aug 30 '14 at 13:34