python获取进程id
How to get the running process’ parent process’ ID in Python?
如何在Python中获取正在运行的进程的“父进程” ID?
In Python, you can get the parent process’ pid by calling os.getppid()
:
在Python中 ,您可以通过调用os.getppid()
获得父进程的pid:
import os
ppid = os.getppid()
One example:
一个例子:
The shell’s pid:
外壳的pid:
$ echo $$
21779
Start a python REPL and get its parent pid (the shell’s):
启动 python REPL并获取其父pid(shell的):
$ python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>>print os.getppid()
21779
>>>
Answered by dtivl.
dtivl回答。
翻译自: https://www.systutorials.com/how-to-get-the-running-process-parent-process-id-in-python/
python获取进程id