gpt4 book ai didi

php exec ('ps -aeo' ) 不返回所有进程

转载 作者:太空宇宙 更新时间:2023-11-04 09:36:02 26 4
gpt4 key购买 nike

我正在尝试构建一个简单的 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"
}
]

最佳答案

我遇到了同样的问题,这个解决了。 (假设你有root权限)

# chcon -t unconfined_exec_t /sbin/httpd

see detailed document here

如果服务器被不信任的用户共享,这可能不是一个好主意

关于php exec ('ps -aeo' ) 不返回所有进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26368465/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com