Python os.getpid() Method
os.getpid() method returns the current Process ID. Every process running inside the operating system will have its own process ID or PID, which is represented as an integer identifier. The
getpid() is a built-in function of the operating system module and comes default with Python.
The syntax of
os.getpid() method is:
os.getpid() method does not take any parameters.
os.getpid() method returns the process ID of the current executing Process. The PID or Process ID will be in the form of an integer.
getpid() method does not take any argument and hence it cannot return.
Example - Get the Process ID using os.getpid() method
os.getpid() function gets the current process ID of the currently executing process. If you are running the code on VSCode the process ID returned would be of Python.exe which is executing the code.
import os print("Current Process ID is:",os.getpid())
Current Process ID is: 29428
os.getpid() method is a built-in function of the operating system module, mainly used to get the process ID of the current executing Process. The PID or Process ID returned will be in the form of an integer.
Reference: Python Official Docs