How to get the running process' parent process' ID in Python?

How to get the running process' parent process' ID in Python?

asked Jun 5 by dtivl (2,500 points)

1 Answer

In Python, you can get the parent process' pid by calling os.getppid():

import os

ppid = os.getppid()

One example:

The shell's pid:

$ echo $$
21779

Start a python REPL and get its parent pid (the shell's):

$ 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 Jun 5 by dtivl (2,500 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...