W3Basic Logo

Python os.getpid() Method

The 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.


Syntax

The syntax of os.getpid() method is:

os.getpid()

Parameters

The os.getpid() method does not take any parameters.

Return Value

The 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.

Note: The getpid() method does not take any argument and hence it cannot return.

Example - Get the Process ID using os.getpid() method

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

Output

Current Process ID is: 29428

Conclusion

The 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

© 2023 W3Basic. All rights reserved.

Follow Us: