Listing all child pid and deleting it in reverse order

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Listing all child pid and deleting it in reverse order
# 1  
Old 03-27-2012
Error Listing all child pid and deleting it in reverse order

Hi ,

My problem is that I am not able to list all process id of any process.

Quote:

[root@server public_html]# pstree -p | grep httpd
|-httpd(17888)-+-httpd(9134)
| |-httpd(9136)-+-{httpd}(9140)
| | |-{httpd}(9141)
| | |-{httpd}(9142)
| | |-{httpd}(9143)
| | |-{httpd}(9144)
| | `-{httpd}(9145)
| `-httpd(12594)-+-{httpd}(12596)
| |-{httpd}(12597)
| |-{httpd}(12598)
| |-{httpd}(12599)
| |-{httpd}(12600)
| `-{httpd}(12601)
If you see pstree command it shows many process id under https. But if I run ps command its not listing all the process id for httpd.

Quote:
[root@server public_html]# ps auwx | grep http | grep -v grep
apache 9134 0.0 1.3 46544 10060 ? S 16:36 0:00 /usr/local/apache/bin/httpd -k restart
apache 9136 0.0 6.1 149656 47728 ? Sl 16:36 0:01 /usr/local/apache/bin/httpd -k restart
apache 12594 0.0 2.0 114180 16040 ? Sl 19:51 0:00 /usr/local/apache/bin/httpd -k restart
root 17888 0.0 1.7 46676 13256 ? Ss Mar22 0:05 /usr/local/apache/bin/httpd -k restart
It is just listing the PPID and immediate child process id only. I want to have all child process id.

Why pstree and ps command output is different.

Can someone point me in the right direction so that I can get all the child process id using other command rather than using pstree command.

Thank you


---------- Post updated at 09:08 PM ---------- Previous update was at 09:08 PM ----------

I have managed to write one line script to get the list all process id of HTTPD including PPID TGID and PID

Quote:
for i in `ps auwx | grep http | grep -v grep | awk {'print $2'}`; do ls -1 /proc/$i/task ; done
# 2  
Old 03-27-2012
You can avoid the 'grep -v grep' by altering the pattern so it doesn't match itself:

Code:
grep '[h]ttp'

# 3  
Old 03-28-2012
you could also just do a killall httpd
# 4  
Old 03-28-2012
@Mark : Yes that is what i know.

Why pstree and ps command output is different?
# 5  
Old 03-31-2012
The pstree command shows processes and threads. The ps command by default only shows processes (ps -eLf shows threads as well)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting child process id for a given PID

HI Am trying to get child process id for a PID using ksh.. ps -ef | grep xntpd root 3342472 2228308 0 12:17:40 - 0:00 /usr/sbin/xntpd root 4522024 6488316 0 12:18:56 pts/0 0:00 grep xntpd root 6291614 3342472 0 12:17:40 - 0:00 /usr/sbin/xntpd Here now i... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

2. Shell Programming and Scripting

print in reverse order

Hi, I want to print the item in reverse order such that the output would look like 00 50 50 23 40 22 02 96 Below is the input: 00 05 05 32 04 22 20 69 Video tutorial on how to use code tags in The UNIX and Linux Forums. (5 Replies)
Discussion started by: reignangel2003
5 Replies

3. Homework & Coursework Questions

Need help with deleting childīs parent and child subprocess

1. The problem statement, all variables and given/known data: I need to make an program that in a loop creates one parent and five children with fork(). The problem i'm trying to solve is how to delete the parent and child of the childīs process. 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: WhiteFace
0 Replies

4. Shell Programming and Scripting

How to get fields in reverse order?

i am having lines like below seperated by "|" (pipe) abc|xyz 123|567 i have to get the above in reverse order xyz|abc 567|123 Pls help (5 Replies)
Discussion started by: suryanarayana
5 Replies

5. Shell Programming and Scripting

how to capture PID for a child script

Hi, I'm looking for a method where we can capture the PID and if possible the progress of child process especially the ones running in background. can anyone help? (6 Replies)
Discussion started by: aman jain
6 Replies

6. UNIX for Dummies Questions & Answers

sort -reverse order

I need to sort the particular column only in reverse order how i can give it.. if i give the -r option the whole file is getting sorted in reverse order. 1st 2nd col 3rd C col 4th col 5th col ------------------------------------------- C... (7 Replies)
Discussion started by: sivakumar.rj
7 Replies

7. Shell Programming and Scripting

child pid in ZSH

I am using ZSH shell in Linux. I am calling a child program in background mode parallely (say 2-3 threads). I have problem in handling the temporary files of these child programs since the temp file names are unique for all the child process. To distinguish i want to use the pid in the temp... (3 Replies)
Discussion started by: dhams
3 Replies

8. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies

9. Programming

Child Process PID

Hi, Can anybody solve this query? A parent process forks 2 child processes. How does the child process know it's PID without the parent process sending it. Apart from the "ps-ef" option, what other options are there if any? (2 Replies)
Discussion started by: skannan
2 Replies
Login or Register to Ask a Question