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

时间:2014-10-14 19:08:30

标签: php linux apache centos ps

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

1 个答案:

答案 0 :(得分:2)

我有同样的问题,这解决了它。 (假设您拥有root权限)

# chcon -t unconfined_exec_t /sbin/httpd

see detailed document here

如果服务器由不信任的用户共享,那么

可能不是一个好主意