32

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?

0

1 Answer 1

47

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. 
2
  • 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. Commented Jun 21, 2017 at 13:49
  • 2
    For 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, /Angel Commented Dec 1, 2017 at 11:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.