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

  • Home
  • SEARCH
  • 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 7779251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:36:11+00:00 2026-06-01T18:36:11+00:00

I’ve seen several questions like this one, but after trying various variants of checking

  • 0

I’ve seen several questions like this one, but after trying various variants of checking if the children are alive and exiting the children processes, I simplified the problem and still it will not work.

Am I wrong in exiting a forked process with sys.exit(0)?
Is there another way to kill it. The thing is, I cannot have the parent kill the processes since it won’t know when they’re done working.

At first I thought it was because a executed a system command before exiting (Python run system command and then exit… won't exit), but I’ve even removed that in the simplified version as given solution didn’t work either.

Here’s an example:

import sys
import os
import time

children = []

for i in range(0,3):    
    pid = os.fork()

    if pid == -1:
        continue
    elif pid == 0:
        # Do work...
        print 'Child %d spawned' % os.getpid()
        sys.exit(0)     
    else:
        children.append(pid)

time.sleep(5)
for pid in children:
    proc_path = '/proc/%d' % pid
    if not os.path.exists(proc_path):
        print 'Child %d is dead' % pid
    else:
        print 'Child %d is alive' % pid

This prints:

Child 27636 spawned
Child 27637 spawned
Child 27638 spawned
Child 27636 is alive
Child 27637 is alive
Child 27638 is alive

But child processes should be dead.

What causes these processes to become zombies in this case?

  • 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-01T18:36:13+00:00Added an answer on June 1, 2026 at 6:36 pm

    You have to wait() for the child-process.

    Please add the following lines to get things corrected:

    import sys
    import os
    import time
    
    children = []
    
    for i in range(0,3):    
        pid = os.fork()
    
        if pid == -1:
            continue
        elif pid == 0:
            # Do work...
            print 'Child %d spawned' % os.getpid()
            sys.exit(0)     
        else:
            children.append(pid)
    
    time.sleep(5)
    
    # ADD NEXT TWO LINES:
    for pid in children:
        os.waitpid(pid, 0)
    
    for pid in children:
        proc_path = '/proc/%d' % pid
        if not os.path.exists(proc_path):
            print 'Child %d is dead' % pid
        else:
            print 'Child %d is alive' % pid
    

    The parent must wait() for the child. Please see man 2 waitfor details.

    In python you can handle those things with the subprocess module.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the

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.