LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   PS output: About root service & it leafs. (https://www.linuxquestions.org/questions/linux-newbie-8/ps-output-about-root-service-and-it-leafs-738645/)

CrAzYoNi 07-08-2009 11:15 AM

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.

chrism01 07-08-2009 07:39 PM

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.

CrAzYoNi 07-11-2009 08:59 AM

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.


All times are GMT -5. The time now is 07:28 PM.