Blog

Python | Get Process Pid And Parent Process Pid

Context

Question

How to determine if running current process is parent?

Answer

import os

## Answer

pid = os.getpid()
parent_pid = os.getppid()

https://stackoverflow.com/a/23539446/3627387

import psutil, os
psutil.Process(os.getpid()).ppid()

What I Learned

Resources

Tags: