【问题标题】:php exec('ps -aeo') doesn't return all processesphp exec('ps -aeo') 不返回所有进程
【发布时间】: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


【解决方案1】:

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

# chcon -t unconfined_exec_t /sbin/httpd

see detailed document here

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

【讨论】:

    猜你喜欢
    • 2017-08-18
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 2011-08-01
    • 2010-10-20
    相关资源
    最近更新 更多