简体   繁体   English

如何获得top命令的输出

[英]How to get output of top command

I'm wondering how to get the output of the 'top' command. 我想知道如何获取“ top”命令的输出。 I'm looking to obtain the number of currently running processes. 我正在寻找当前正在运行的进程数。

I tried putting it to a text file and got garbage. 我试着将其放入文本文件中,并产生了垃圾。 I'm unsure on how to approach this. 我不确定该如何处理。 My assignment is to determine the number of processes considered by the short-term scheduler for process allocation (processes currently ready to run) at any given time. 我的任务是确定短期调度程序在任何给定时间为进程分配(当前准备运行的进程)考虑的进程数。

Use top in batch mode: 在批处理模式下使用top:

top -bn1 > output.txt

See also this previous answer . 另请参阅此先前的答案

比解析顶部更容易,您可以在进程列表中计算行数:

ps -ef | wc -l

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM