获取非交互式 shell 的 `top` 输出

jcu*_*bic 18 scripting top

我想为 Web 应用程序实现 top 功能。是否可以top在非交互式 shell 中获取命令的输出?

joe*_*epd 26

top -b -n 1

来自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.
Run Code Online (Sandbox Code Playgroud)