Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a quite fresh install of the Apache (2.2.3/Centos) + PHP(5.1.6) and following problem: I need to monitor life of one process and in order to do that I run:

$last_line = exec('ps -C snmpd');

and check its output.

Unfortunately I always get nothing. I've checked it with other process names and it seems it can 'see' only Apache's processes.

Any idea how to work this out?

UPDATE: Execution of the other command system('snmpget -v2c -c public localhost '.$oid, $retval); works great, there is only problem with the ps. What is strange (for me), when I log as apache user and run ps manually it works correctly (shows everything).

share|improve this question
    
I've found the other way. It's not the right solution for the problem but in this particular case it works. My workaround is to check if /var/run/snmpd.pid file exists. –  Satanowski May 11 '10 at 13:07
add comment

4 Answers

You will only be able to see the processes of the user under which the web server is running, as this is the user exectuing the command.

If you require the ability to run commands as a different user, have a look at suexec. http://httpd.apache.org/docs/2.2/suexec.html

share|improve this answer
    
Strange. I can get full process list as the "apache" user ... and this 'exec' way have worked before on Gentoo :/ –  Satanowski May 11 '10 at 10:58
add comment

Try running a fuller ps call like:

ps aux | grep -i snmpd | grep -v grep
share|improve this answer
    
That was the first version of my script, before I've changed it to exec('ps -C snmpd'). It also fails. –  Satanowski May 11 '10 at 12:59
add comment

You might also use backtick operator to achieve the same thing. I confirm it works while exec doesn't.

$out = `ps -aux|grep pianobarfly|grep -v grep`;

share|improve this answer
1  
the use of $( ... ) is preferred these days. –  Iain Nov 7 '11 at 11:21
add comment

Probably selinux. SELinux restricts the domain that httpd runs in so it can only view its own processes.

You can either:-

  1. Turn off selinux (wouldnt recommend that) - setenforce 0
  2. Make httpd not use selinux (not recommend that either because httpd is a likely attack vector) setsebool -P httpd_disable_trans = 1. Restart httpd.
  3. Change the policy to permit seeing processes in /proc.

This should do it:-

policy_module(myhttpd,1.0.0)

gen_require(`
    type httpd_t;
')

kernel_read_system_state(httpd_t);

Install selinux-policy-devel from yum.

Then run the command "make -f /usr/share/selinux/devel/Makefile load" to insert the new module.

You should see an immediate result.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.