python start process in background and get pid

Solutions on MaxInterview for python start process in background and get pid by the best coders in the world

showing results for - "python start process in background and get pid"
Carlos
10 Aug 2020
1from subprocess import Popen
2
3# Subprocess Command
4cmd = "python3 another_process.py"
5p = Popen(cmd.split())
6print("Process ID:", p.pid)
7
8# Check the status of process
9# poll() method returns 'None' if the process is running else returns the exit code
10print(p.poll())