Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 741
genesis Avatar asked Nov 29 '22 10:11

genesis


1 Answers

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

like image 165
MK. Avatar answered Dec 06 '22 10:12

MK.