Tuesday, December 13, 2005

Use pstree to See Your Tree of Subshells

Execute the command csh. The prompt changes! You are now running an older shell, csh, that has a different syntax. Try, for example, typing in a comment, like this
# this is a comment 
This new shell is a subshell of the bash you were talking to a minute ago. Exit the subshell, and you'll see you're back in the parent shell. You can see
this with the ps command.

ps -o pid,ppid,args
csh
ps -o pid,ppid,args
exit
ps -o pid,ppid,args
Each running program is a process, with an identifying number, or Process ID. If that process is a subprocess of some other program, then the ps command shown above also shows the Parent Process ID.

You should be able to trace out what's a child of what in the listings above, pretty easily.

Actually, in Linux, every process is the child of another process, except for the very first process, which is called init. Look:

pstree -A -p | less
The numbers in parens are PIDs. Try invoking some subshells and watch how the process tree changes.

0 Comments:

Post a Comment

<< Home