call the top command in non-interactive mode through other programs or scripts, often appear :
top: failed tty get error
solution: add the -b option to either
-b: Batch mode operation
Starts top in < A1> < AF> Batch mode< A1> < AF> You< 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< A1> < AF> ve set with the < A1> < AF> -n< A1> < AF> command-line option or until killed.
for example: top-bn 1
nohup top-b | grep init > > top.log & (Top. Log content is displayed slowly)
nohup /usr/bin/top -b | grep init > > top.log & (top. Log content appears fast)