Getting the running process’ own pid in Python

Posted on In Programming, QA

How to get the running process’ pid in Python?

In Python, you can get the pid of the current process by

import os

os.getpid()

From the official doc:

os.getpid()
    Return the current process id.

One example os using os.getpid() to get process own ID:

$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getpid()
25128
>>> 

One comment

Leave a Reply

Your email address will not be published.