Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8420201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:49:39+00:00 2026-06-10T02:49:39+00:00

I use a lot of os.system calls to create background processes inside a for

  • 0

I use a lot of os.system calls to create background processes inside a for loop. How can I wait for all the background processes to end ?

os.wait tells me there are no child process.

ps: I am using Solaris

here is my code :

#!/usr/bin/python
import subprocess
import os

pids = []
NB_PROC=30

for i in xrange(NB_PROC):
        p = subprocess.Popen("(time wget http://site.com/test.php 2>&1 | grep real )&", shell=True)
        pids.insert(0,p)
        p = subprocess.Popen("(time wget http://site.com/test.php 2>&1 | grep real )&", shell=True)
        pids.insert(0,p)

for i in xrange(NB_PROC*2):
        pids[i].wait()
os.system("rm test.php*")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:49:41+00:00Added an answer on June 10, 2026 at 2:49 am

    Normally, os.system() returns when the child process is finished. So there is indeed nothing for os.wait() to do. It is equivalent to subprocess.call().

    Use subprocess.Popen() to create background processes, and then the wait() or poll() methods of the Popen objects to wait for them to quit.

    By default, Popen does not spawn a shell but executes the program directly. This saves resources and prevents possible shell injection attacks.

    According to the documentation for os.system():

    The subprocess module provides more powerful facilities for spawning
    new processes and retrieving their results; using that module is
    preferable to using this function

    If you want to do multiple jobs in parallel, consider using multiprocessing, especially the Pool object. It takes care of a lot of the details of farming work out over several processes.

    Edit: Timing the execution of a program;

    import time
    import subprocess
    
    t1 = time.clock()
    t2 = time.clock()
    overhead = t2-t1
    
    t1 = time.clock()
    subprocess.call(['wget', 'http://site.com/test.php'])
    t2 = time.clock()
    print 'elapsed time: {:.3f} seconds.'.format(t2-t1-overhead)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I use JScript (Microsoft's ECMAScript implementation) for a lot of Windows system administration
I am developing a simple informative system which will use a lot of images.
I use a lot of Sencha stores in my app. Is there a way
I'm rewriting a Ruby program in C#. It has a lot of system() calls
Our applications use lot of custom built and third party libraries and right now
I use a lot of lines like that Console.WriteLine(Test); to debug application under VS
I use a lot of iterations to define convenience methods in my models, stuff
I have a bizarre problem. I use a lot of session variables so I
I am writing a client-side .NET application which is expected to use a lot
I use this a lot NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES comparator:^(id obj1, id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.