From: tazimk on 26 Jul 2010 00:02 Hi, I am using python's multiprocessing module to spawn new process as follows : import multiprocessing import os d = multiprocessing.Process(target=os.system,args=('iostat 2 > a.txt',)) d.start() I want to obtain pid of iostat command or the command executed using multiprocessing module When I execute : d.pid it gives me pid of subshell in which this command is running . Any help will be valuable . Thanks in advance
From: Chris Rebert on 26 Jul 2010 00:29 On Sun, Jul 25, 2010 at 9:02 PM, tazimk <tazimkolhar(a)gmail.com> wrote: > Hi, > > I am using python's multiprocessing module to spawn new process > > as follows : > > import multiprocessing > import os > d = multiprocessing.Process(target=os.system,args=('iostat 2 > > a.txt',)) > d.start() > > I want to obtain pid of iostat command or the command executed using > multiprocessing module `multiprocessing` isn't the best module for this; use `subprocess` instead: from subprocess import Popen, PIPE process = Popen(["iostat"], stderr=open("a.txt", 'w'), stdout=PIPE) print("the PID is", process.pid) `multiprocessing` is used for parallelism in Python code, as an alternative to threads. `subprocess` is used for running external commands, as a preferred alternative to os.system() among other things. Cheers, Chris -- http://blog.rebertia.com
|
Pages: 1 Prev: Python acting weird Next: Undo-Redo, copy instance, custom events and a problem |