FAQ
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

Search Discussions

  • Chris Rebert at Jul 26, 2010 at 4:29 am

    On Sun, Jul 25, 2010 at 9:02 PM, tazimk 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 26, '10 at 4:02a
activeJul 26, '10 at 4:29a
posts2
users2
websitepython.org

2 users in discussion

Tazimk: 1 post Chris Rebert: 1 post

People

Translate

site design / logo © 2022 Grokbase