I was trying to execute this command
echo exec("top");
and
echo exec("/usr/bin/top");
neither works (returns blank output)
does anybody know why?
I was trying to execute this command
echo exec("top");
and
echo exec("/usr/bin/top");
neither works (returns blank output)
does anybody know why?
It probably works, but
exec()
doesn't return anything. Read the Manual:exec()
But you have another problem:
top
doesn't exit by itself. You cannot use it here, because you need to send the interrupt-signal (just realized:q
is ok too).One solution is to make
top
to stop after one iterationYou actually can call top and echo its output. Code that worked for me:
-b - running in batch mode
-n 1 - only one iteration
I used:
100% minus the idle time.
Because top is an interactive program that is meant to be run on a terminal, not be executed from a script. You are probably want to run the 'ps' command with arguments which will sort output by cpu utilization. http://www.devdaily.com/linux/unix-linux-process-memory-sort-ps-command-cpu
If you want to put it in a variable :