I tried this way: <?php exec("ps aux" , $psOutput); print_r($psOutput); ?> ALso tried even only ps But all i got as output was: [0] => USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND [1] => apache 1102 0.0 0.0 2288 508 ? R 13:13 0:00 ps aux [2] => apache 9035 0.0 0.6 29012 12600 ? S Jan09 1:05 /usr/sbin/httpd [3] => apache 9036 0.1 0.6 28636 12380 ? S Jan09 1:08 /usr/sbin/httpd [4] => apache 9037 0.1 0.6 28892 12720 ? S Jan09 1:21 /usr/sbin/httpd [5] => apache 9038 0.1 0.6 28892 12532 ? S Jan09 1:10 /usr/sbin/httpd [6] => apache 9039 0.1 0.5 27632 11208 ? S Jan09 1:10 /usr/sbin/httpd [7] => apache 9040 0.1 0.7 31560 15188 ? S Jan09 1:09 /usr/sbin/httpd [8] => apache 9041 0.0 0.6 28892 12388 ? S Jan09 0:58 /usr/sbin/httpd [9] => apache 9042 0.0 0.4 26448 9836 ? S Jan09 0:57 /usr/sbin/httpd [10] => apache 9299 0.1 0.4 26448 9996 ? S Jan09 1:09 /usr/sbin/httpd [11] => apache 9300 0.1 0.6 29228 12748 ? S Jan09 1:15 /usr/sbin/httpd [12] => apache 9301 0.1 0.6 29308 12800 ? S Jan09 1:09 /usr/sbin/httpd Code (markup): Where is all other processes ??
The script will be running as user nobody or your webserver user - which is why all your seeing is apache.. I dont know how to do it, but you would need the script to be able to run as as user with permission to see all of the running processes - perhaps root (probably not the best idea) or by using sudo somehow?
I use centos 5.9 if that helps, but i think there is no way to do it, seems like its somehow protecting me from viewing other things like processes. I also tried another way that php calling shell script, and inside *.sh script is ps aux but no luck.
The problem is that the user issuing the 'ps aux' command is your webserver user - usually nobody. The user nobody doesnt have permission to view any running processes other than its own. I thought you might be able to structure your code somehow to have the command run as a different user, but this is something im not familiar with so its nothing more than a guess. However I just did a quick search and found this: "You should also bear in mind that PHP will not run as a process (unless its CLI) as it will be invoked from apache, or your web server" If you can put apache in to cgi mode this should allow you to achieve what your trying, but may mean compatibility with other scripts or sites running under apache may be affected.
If you want the complete list, run as root. There are many ways to do that, here are some ways: http://stackoverflow.com/questions/1598231/how-to-run-php-exec-as-root
Just out of curiosity why do you need to fetch all running processes from a PHP script executed by the web server? If you were creating some sort of administration script couldn't you run the php script locally via command line?