【发布时间】:2014-10-14 19:08:30
【问题描述】:
我正在尝试构建一个简单的 php 脚本来返回一个 JSON 格式的运行进程列表。
这个脚本当然是由apache执行的。
除了一个小细节,我什么都想明白了。当脚本由 apache 执行时,该命令仅返回 'apache' 用户拥有的正在运行的进程列表。
这里面还有吗?
exec('ps -aeo',$output);
//then some code to parse the $output and return a JSON string
输出:
"processes": [
{
"cpu": "0.0",
"pid": "23698",
"user": "apache",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "23486",
"user": "apache",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "23485",
"user": "apache",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "23484",
"user": "apache",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "23483",
"user": "apache",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "23482",
"user": "apache",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "23481",
"user": "apache",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "23480",
"user": "apache",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "23479",
"user": "apache",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "23478",
"user": "apache",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "1008",
"user": "root",
"command": "/usr/sbin/httpd"
},
{
"cpu": "0.0",
"pid": "959",
"user": "root",
"command": "/usr/sbin/abrtd"
}
]
【问题讨论】:
-
尝试 'ps aux' 解除“仅限此用户”限制。
-
@cwscribner 打败我。是的。尽管您最终可能会因此而遇到一些格式问题,但请像
strikethrough一样糟糕。 -
我最近刚做了类似的事情。也许看看我的代码会对你有所帮助;)geneticcoder.blogspot.com/2014/10/…
-
@cwscribner 'aux' 没有运气,仍然只输出 apache 拥有的进程。
-
@Ohgodwhy 可悲的是没有工作
标签: php linux apache centos ps