【发布时间】:2015-03-23 13:05:04
【问题描述】:
当我使用 ssh 命令行运行 ps cax 时,我得到以下信息:
user@dqeb ~ $ ps cax
PID TTY STAT TIME COMMAND
3277 ? Ss 12:51 httpd
6797 ? S 1:45 httpd
7190 ? Ss 0:00 gpopd.pl
7291 ? S 0:02 httpd
7303 ? S 0:05 httpd
7309 ? S 0:03 httpd
7336 ? S 0:02 httpd
7361 ? S 0:03 httpd
7419 ? S 0:02 httpd
7426 ? S 0:02 httpd
7427 ? R 0:03 httpd
7440 ? S 0:02 httpd
7457 ? S 0:01 httpd
7468 ? S 0:01 httpd
7504 ? S 0:02 httpd
7743 ? S 0:00 wrapper
7744 ? Sl 0:00 java
7812 ? S 0:00 qmail-local
7843 ? S 0:00 qmail-local
7848 pts/3 R+ 0:00 ps
8769 ? Sl 0:00 sshd
8775 pts/5 Ss+ 0:00 bash
9159 pts/2 S 0:00 su
9160 pts/2 S+ 0:00 bash
9241 pts/5 S 0:00 gimap.pl
30334 ? S 0:00 imap
30335 ? S 0:00 imap
30340 ? S 0:00 imap
30582 ? Sl 0:00 sshd
30589 pts/3 Ss 0:00 bash
但是,当我运行以下 PHP 代码时:
$newline = chr(10);
$out = `ps cax`;
$out = str_replace($newline, '<br>', $out);
echo $out;
我明白了
7519 ? R 0:00 ps
15886 ? S 0:00 httpd
15890 ? S 0:00 httpd
15891 ? S 0:00 httpd
15917 ? S 0:00 httpd
15920 ? S 0:00 httpd
15930 ? S 0:00 httpd
15932 ? S 0:00 httpd
15933 ? S 0:00 httpd
16124 ? S 0:00 httpd
16125 ? S 0:00 httpd
16126 ? S 0:00 httpd
16128 ? S 0:00 httpd
16129 ? S 0:00 httpd
16130 ? S 0:00 httpd
16131 ? S 0:00 httpd
16134 ? S 0:00 httpd
16137 ? S 0:00 httpd
16138 ? S 0:00 httpd
16448 ? S 0:00 httpd
..这样持续了很长时间。
为什么我在同一台服务器上运行相同的命令时看不到相同的进程?我希望它们是相同的。
【问题讨论】:
-
怀疑输出中有
tab符号,但 HTML 呈现为简单的空格。尝试在元素中渲染输出
-
我说的不是格式,而是实际的过程。
-
请试试这个:sudo su www-data ps cax 如果进程列表不完整,请看下面我的回答。
-
@SofianeSadi 我没有根权限
-
您是否以 httpd 用户身份运行该脚本?如果是这样,它将仅显示该用户可用的进程。
标签: php shell command shell-exec backticks