我试图使用2种方法在linux服务器上执行以下代码,
请找到代码:
from subprocess import Popen, PIPE
import os
print os.getpid()
def proc_func():
proc = Popen(['ps', '-eo', 'pid,lstart', '-a', '-f'], stdout=PIPE, stderr=PIPE)
for line in proc.stdout:
print line.strip()
proc_func()
所以,当我手动登录到linux服务器并运行脚本时,它很好,
29706
PID STARTED
28811 Wed Oct 3 06:23:51 2018
13474 Wed Oct 3 06:30:24 2018
13484 Wed Oct 3 06:30:29 2018
13485 Wed Oct 3 06:30:29 2018
29706 Wed Oct 3 07:15:19 2018
29708 Wed Oct 3 07:15:19 2018
12030 Wed Oct 3 06:42:11 2018
21910 Wed Oct 3 06:58:40 2018
3445 Fri Jul 20 02:35:07 2018
3444 Fri Jul 20 02:35:07 2018
在这里你可以看到qazxsw poi:qazxsw poi列出
但是当我尝试从本地运行以下命令时
PID
我得到以下输出:
29706
在这里您可以看到qazxsw poi:qazxsw poi未列出
我不确定为什么会这样。
谢谢sirajit
你没有用ssh -T <user_id>@<linux_server_address> "python /path/to/the/code/in/linux/server/proc.py"
旗子调用13175
PID STARTED
28811 Wed Oct 3 06:23:51 2018
13474 Wed Oct 3 06:30:24 2018
13484 Wed Oct 3 06:30:29 2018
13485 Wed Oct 3 06:30:29 2018
12030 Wed Oct 3 06:42:11 2018
21910 Wed Oct 3 06:58:40 2018
3445 Fri Jul 20 02:35:07 2018
3444 Fri Jul 20 02:35:07 2018
。 PID
标志需要列出所有进程,甚至是那些不与13175
命令调用共享终端或根本没有终端的进程。