Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-08-2009, 11:15 AM   #1
Registered: Sep 2008
Posts: 36

Rep: Reputation: 0
Question PS output: About root service & it leafs.

Hi all,

Introduction to my question: I'm writing a script (In Perl) for checking if the Apache Web service is up - and if so, I want the script to check more things.

- I want the script to get the primary PID number of the Apache2 service.
- I want the script to count the amount of apache processes that are running.

I'm using the command: ps -eo pid,ppid,comm.

On my system, while I tested it, always the root process of Apache was output first & below it all of it's leas when the root process pid was as the ppid in the Apache process leafs.

My question is: Should it always be like that? or it might sometimes that Apache leaf process will be output above to the root Apache process?

Here is example to my current output, which is fine with me!
CrAzYoNi@Every1:~$ ps -eo pid,ppid,comm | grep apache
10326 1 apache2
20451 10326 apache2
20457 10326 apache2
20467 10326 apache2
20470 10326 apache2
20475 10326 apache2
20480 10326 apache2
20483 10326 apache2
20484 10326 apache2
20491 10326 apache2
20496 10326 apache2
Thanks in advance!

Yoni D.
Old 07-08-2009, 07:39 PM   #2
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,407

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
I wouldn't assume it, just to be careful. Add the flags -u or -U to specify you want the root or apache/httpd owned processes.
Theoretically you could just use the ppid=1 to get root owned process, but its more generic to check the user, just in case apache wasn't started by init.
Old 07-11-2009, 08:59 AM   #3
Registered: Sep 2008
Posts: 36

Original Poster
Rep: Reputation: 0
chrism01, thanks!! you really helped me.
I decided to work with the commands:
ps -eo pid,ppid,comm,user --user root
For detecting the root process of Apache2.

ps -eo pid,ppid,comm,user --user www-data
For detecting apache2 leafs processes.

Thanks a lot!!

Yoni D.

Last edited by CrAzYoNi; 07-11-2009 at 09:00 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I access "Root" & Root Privileges? Thouroughly Confused & Frustrated! geotev Linux - Networking 2 08-06-2007 05:58 PM
How to redirect to a file the output of a service? rtmex Linux - Newbie 5 04-26-2007 11:09 PM
root autologin and lampp service chobin SUSE / openSUSE 1 10-27-2006 08:51 AM
NO service command in root director johnrage Linux - Newbie 6 12-07-2005 10:48 AM
Starting a service as non root user? dee3lmo Linux - General 2 07-30-2004 07:37 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:31 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration