Getting the running process’ own pid in Python

How to get the running process’ pid in Python?

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

import os


From the official doc:

    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()

One comment:

Leave a Reply

Your email address will not be published. Required fields are marked *