在python中打开具有特定pid的进程

SuB*_*SuB 1 python pid process

如何在 python 中使用特定的 pid打开进程。我的意思是我想设置进程PID。

编辑:

我想确定我已经运行的进程的PID(例如使用类Popen的方法subprocess

Alf*_*lfe 5

PID 由操作系统给出,您不能为子进程使用特定的 PID。

要确定子进程的 PID,您可以向子进程询问:

import subprocess

dateProc = subprocess.Popen([ 'date' ])
print dateProc.pid
Run Code Online (Sandbox Code Playgroud)

如果您想知道当前进程的 PID,请使用os.getpid()