How to determine pid of process started via os.system

前端 未结 3 510
南笙
南笙 2020-12-19 04:51

I want to start several subprocesses with a programm, i.e. a module foo.py starts several instances of bar.py.

Since I sometimes have to te

3条回答
  •  旧时难觅i
    2020-12-19 05:27

    Sharing my solution in case it can help others:

    I took the info from this page to run a fortran exe in the background. I tried to use os.forkpty to get the pid of it, but it didnt give the pid of my process. I cant use subprocess, because I didnt find out how it would let me run my process on the background.

    With help of a colleague I found this:

    exec_cmd = 'nohup ./FPEXE & echo $! > /tmp/pid'
    
    os.system(exec_cmd)
    

    In case of wanting to append pids to the same file, use double arrow.

提交回复
热议问题