Pawan Adhikari Pawan Adhikari - 1 year ago 48
Linux Question

You get an 'aux ps' output where only 1 terminal was opened and a.out was executed 2 times, but you only called it once. Something in the trend of

enter image description here

The questions are as follows:

  1. How can we see from the above picture that only one terminal are open?

  2. Is it true that there is one parent process and two child processes? How can you say that? Can we determine the states of parent and the child?

Rob Rob
Answer Source

In Linux often times a sub-process or thread (light weight sub process) will appear bellow the parent with the exact same signature and look like there are two or more of the same processes running.

If you do a

 ps -efH | grep a.out 

you should see that tree structure, you can also observe it in htop by turning on the tree view (F5). Or do a

 pstree -clap <pid of parent process>

You can use the parent terminal process too, it will give you the process and all its children. So from the terminal you are about to run a.out do

 echo $$ 

that will give you its process, start a.out then in another terminal use the process id you just got in the pstree command.