On this page
os.getpid
Prev: os.getenv | Up: os | Next: os.getppid
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.getpid
Tags: #public #python3 #stdlib #os
Import
import os
from os import getpid
Signature & Overview
os.getpid()
Return the current process id.
Usage
import os
pid = os.getpid()
assert isinstance(pid, int) and pid > 0
Gotchas
- Unique while the process is alive: Useful in log formats, lockfiles, and temporary filenames.
REPL Inspect
from os import getpid
help(getpid)
Linked from
Related notes
- tuts/python3/stdlib_module/os/getenv Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/getppid Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/os/abort Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/access Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chdir Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chmod Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chown shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/close shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/cpu_count shared tags: #os, #stdlib