I want to implement top function for a web app. Is it possible to get the output of the top command in non-interactive shell?
1 Answer
top -b -n 1
From man top:
-b : Batch mode operation Starts top in 'Batch mode', which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' command-line option or until killed.
-
so if i want to add a column in non interactive mode. say i want to add swap usage by process how do i do that ? usually in interactive mode this is what i do : shift + f ----> press p ---> hit enter.Sagar– Sagar2017-06-21 13:49:36 +00:00Commented Jun 21, 2017 at 13:49
-
2For completeness, answering Sagar's question: When running top in interactive mode you can choose columns and orderings, then press "W" to save $HOME/.toprc . This file will be read in next calls to "top", be interactive or not. Simply remove that file to return to defaults. Regards, /AngelAngel– Angel2017-12-01 11:22:52 +00:00Commented Dec 1, 2017 at 11:22