为什么不执行("top");在Linux上工作? [英] Why doesn't exec("top"); work on Linux?

查看:126
本文介绍了为什么不执行("top");在Linux上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行此命令

echo exec("top");

echo exec("/usr/bin/top");

均无效(返回空白输出)

neither works (returns blank output)

有人知道为什么吗?

推荐答案

因为top是一个交互式程序,旨在在终端上运行,而不是从脚本中执行.您可能需要运行带有参数的"ps"命令,这些参数将按cpu利用率对输出进行排序. http://www.devdaily.com/linux /unix-linux-process-memory-sort-ps-command-cpu

Because top is an interactive program that is meant to be run on a terminal, not be executed from a script. You are probably want to run the 'ps' command with arguments which will sort output by cpu utilization. http://www.devdaily.com/linux/unix-linux-process-memory-sort-ps-command-cpu

这篇关于为什么不执行("top");在Linux上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆