LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 11:15 AM   #1
CrAzYoNi
Member
 
Registered: Sep 2008
Posts: 37

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, 07:39 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 08:59 AM   #3
CrAzYoNi
Member
 
Registered: Sep 2008
Posts: 37

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 09:00 AM.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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
Open Source Consulting | Domain Registration