LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 07-08-2009, 12:15 PM   #1
CrAzYoNi
Member
 
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!
Quote:
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!

Yours,
Yoni D.
 
Old 07-08-2009, 08:39 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
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.
http://linux.die.net/man/1/ps
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, 09:59 AM   #3
CrAzYoNi
Member
 
Registered: Sep 2008
Posts: 36

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

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

Thanks a lot!!

Cheers,
Yoni D.

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


Reply


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 06:58 PM
How to redirect to a file the output of a service? rtmex Linux - Newbie 5 04-27-2007 12:09 AM
root autologin and lampp service chobin SUSE / openSUSE 1 10-27-2006 09:51 AM
NO service command in root director johnrage Linux - Newbie 6 12-07-2005 11:48 AM
Starting a service as non root user? dee3lmo Linux - General 2 07-30-2004 08:37 PM


All times are GMT -5. The time now is 12:05 PM.

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