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 418629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:41:51+00:00 2026-05-12T18:41:51+00:00

I got the PID of a process and I need to check if it

  • 0

I got the PID of a process and I need to check if it is a zombie using POSIX system calls in C. How should I do that?

The problem I’m having is that I have a process and it forks into many children, the children all do execs and sometimes I want to do the exec in background so I can’t really wait() the children that go in background. I could wait() periodically (once in my main loop) but I need to know which processes are zombie so my father process doesn’t hang while waiting for children that are not going to end soon.

If you are curious, I’m building a unix shell and it is in the shell nature to have the children processes behaving asynchronously.

  • 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-05-12T18:41:51+00:00Added an answer on May 12, 2026 at 6:41 pm

    You can’t check whether a process is a zombie with pure POSIX calls – except where you’re the parent process, and reaping it with a wait family call. So you’ll have to find a good place to wait for the child.

    One option is to set a SIGCHLD handler and do a waitpid(0, &status, WNOHANG) there. Be sure to loop until it no longer finds any processes – if two children die within a short interval, you may only get one SIGCHLD.

    Another option is to double fork – that is, fork(), have the child (call it child A) fork again, have the second child (child B) exec. Then child A immediately exits. Meanwhile the parent is wait()ing for child A. Once child A is gone, the system’s init process will take care of reaping child B when it eventually dies. This method is simpler, but your shell will have no way of knowing when child B dies, so if you need that information, use the former method.

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

Sidebar

Related Questions

I'm trying to write a daemon process using code igniter library, and the problem
in bash I need to get the pid of a running process whose I
I have to make a java program that when user enters 0 it should
I'm building a monitor app and am having some threading issues. I have, using
I have a java application that got SIG TERM . I want to know
I got the process id of the running service using the code below as
I have a long running process and I need it to launch another process
I've got a memory leak in Upstart init process (pid 1), what options I
I've got this simple bash script that starts a server process. I want to
Got a problem with Apache and PHP-files of Wordpress. When I go to any

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.