phplinuxexectop-command

Why doesn't exec("top"); work on Linux?


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?


Solution

  • 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