pstree but without other children of ancestors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pstree but without other children of ancestors
# 1  
Old 11-04-2012
pstree but without other children of ancestors

Hi, I want to display the process tree of a given PID, however, I don't want to see other children of the ancestors that don't reach the current PID.

My goal is, from the tree result, i have to fetch a particular parent process by keyword, and if any other children from parents have the same name, it will give me incorrect results

I used 'pstree -alhpA <pid>' but it displays the other children of the parents too

Is there a easy way to achieve this without having to write a custom script to loop thru each PPID and reach the root?

Thanks,
-sri
# 2  
Old 11-06-2012
You can probably do it by implementing your own logic: "-f" will give you a output format of "ps" where not only the PID but also the PPID (parent PID) is listed. With this information you can build your own (sub-)tree.

From a certain parent PID search for every process with this PID in the PPID field to get all the children, then repeat this for every child recursively to get your subsection of the tree. If you don't find any children to a process it is one of the "leaves" of the tree and the recursion ends.

The only thing you need to know at the beginning is the PID of the "root" process you want to start your tree with.

I hope this helps.

bakunin
# 3  
Old 11-06-2012
Thanks bakunin, I was hoping there was a built-in utility (similar to pstree) that would accomplish my requirement. I will go ahead and write custom code to navigate from current pid to the root
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script using pstree

Hi guys I am trying to write a script using pstree. I understand what pstree does and how to write the command etc but I want to have a script which adds up all of the processes in the tree to get a whole number instead of the tree list which would normally come out. What I have done so far... (3 Replies)
Discussion started by: simpsa27
3 Replies

2. Shell Programming and Scripting

Doing simple math for children.

Hello! I saw that there were a few differente ways to do math within bash scripts. expr and bc are possibilities. But which one to use when? I want to make an simple bash script for children to do math. The script must ask only questions like 1*1= till 10*10= ... No + or - or /... (10 Replies)
Discussion started by: ugurgazi
10 Replies

3. UNIX for Dummies Questions & Answers

How to use pstree command?

Hi, How to use the pstree command. I tried to execute as below, not able to interpret/understand the output. pstree -p | grep 525 OUTPUT: $ pstree -p | grep 525 ââscsi_eh_0(525) Can anyone throw some light on this? Many thanks. Rgds, (1 Reply)
Discussion started by: venkatesht
1 Replies

4. UNIX for Advanced & Expert Users

difference between pstree and pstree.x11

anyone knows? both commands lies in /usr/bin (3 Replies)
Discussion started by: crackthehit007
3 Replies

5. Shell Programming and Scripting

Killing process and children

Hi all, I have been searching all day for a nice solution to this problem. I have three scripts. A start script, a child script and a stop script. Script A (scripta.sh) Its Child Script B (scriptb.sh) Script C (kill_process.sh $PID) Script A correctly traps the kill command sent from... (6 Replies)
Discussion started by: mark007
6 Replies

6. Linux

pstree problem

hi friends i want to know that which user has loggged from real terminal(konsole) using pstree please help me. (1 Reply)
Discussion started by: praneshmishra08
1 Replies

7. Red Hat

pstree unreadable characters

hi all, i executed this command "pstree" on redhat ent 4 and i got this below with unreadable chars: init─┬─acpid â”─amqzxma0─┬─amqrrmfa │ â”─amqzdmaa │ â”─amqzfuma │ â”─5* │ â”─amqzmgr0─┬─amqpcsea │ │ ... (2 Replies)
Discussion started by: itik
2 Replies

8. Programming

Father & children

Hello, i should finished this program, if anyone could tell me whats wrong... This is an optional university work, though i cant leave this nearly finished. I need to see where is my error :( What my program should do. The user must type "num_proc" ( number of children). The program creates a... (4 Replies)
Discussion started by: Jariya
4 Replies
Login or Register to Ask a Question