Linux系統(tǒng)中top命令是交互式命令,故腳本中執(zhí)行時會卡住,不再執(zhí)行下一個命令。
程序調(diào)用top命令時常會報 top: failed tty get 錯誤,此時使用top -b。
-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.
-n : Number of iterations limit as: -n number
Specifies the maximum number of iterations, or frames, top should produce before ending.