Getting the running process’ own pid in Python
Posted on In Programming, QAHow 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
>>>
you can use os.popen(” pidof “).read() if u are in linux/ unix os