Search code examples
pythonprocesspid

Open process with specific pid in python


How can I open a process in python with specific pid. I mean i want to set process PID.

Edit:

I want determine PID of process which i have been ran with process (e.g. using Popen method of subprocess class)


Solution

  • PIDs are given by the OS, you cannot use a specific PID for your subprocess.

    To determine the PID of a subprocess, you can ask the subprocess for it:

    import subprocess
    
    dateProc = subprocess.Popen([ 'date' ])
    print dateProc.pid
    

    If you meant you want to know the PID of the current process, use os.getpid().