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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:05:00+00:00 2026-05-26T14:05:00+00:00

I have a problem in topic of posix processes and I can’t get around.

  • 0

I have a problem in topic of posix processes and I can’t get around.

I have a process which forks several children (the process tree can be complex, not only one level). It also keeps track of the active childrens’ PID. At some point the parent receives a signal (SIGINT, let’s say).

In the signal handler for SIGINT, it iterates over the list of child processes and sends the same signal to them in order to prevent zombies. Now, the problem is that

  1. if the parent does not waitpid() for the child to be stopped, the signal seems to be never dispatched (zombies keep running)
  2. if the parent waits after every kill() sent to a child, it simply hangs there and the child seems to ignore the signal

Parent and children have the same signal handler, as it’s installed before forking.
Here is a pseudocode.

signal_handler( signal )
    foreach child in children
        kill( child, signal )
        waitpid( child, status )

    // Releasing system resources, etc.
    clean_up()

    // Restore signal handlers.
    set_signal_handlers_to_default()

    // Send back the expected "I exited after XY signal" to the parent by
    // executing the default signal handler again.
    kill( getpid(), signal )

With this implementation the execution stops on the waitpid. If I remove the waitpid, the children keep running.

My guess is that unless a signal handler has ended, the signals sent from it are not dispatched to the children. But why aren’t they dispatched if I omit wait?

Thanks a lot in advance!

  • 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-26T14:05:01+00:00Added an answer on May 26, 2026 at 2:05 pm

    What you describe should work and indeed it does, with the following testcase:

    #include <stdio.h>
    #include <unistd.h>
    #include <signal.h>
    
    #define NCHILDREN 3
    pid_t child [NCHILDREN];
    
    struct sigaction sa, old;
    
    static void
    handler (int ignore)
    {
      int i;
    
      /* Kill the children.  */
      for (i = 0; i < NCHILDREN; ++i)
        {
          if (child [i] > 0)
            {
              kill (child [i], SIGUSR1);
              waitpid (child [i], 0, 0);
            }
        }
    
      /* Restore the default handler.  */
      sigaction (SIGUSR1, &old, 0);
    
      /* Kill self.  */
      kill (getpid (), SIGUSR1);
    }
    
    int
    main ()
    {
      int i;
    
      /* Install the signal handler.  */
      sa.sa_handler = handler;
      sigemptyset (&sa.sa_mask);
      sa.sa_flags = 0;
      sigaction (SIGUSR1, &sa, &old);
    
      /* Spawn the children.  */
      for (i = 0; i < NCHILDREN; ++i)
        {
          if ((child [i] = fork ()) == 0)
            {
              /* Each of the children: clear the array, wait for a signal
                 and exit.  */
              while (i >= 0)
                child [i--] = -1;
              pause ();
              return 0;
            }
        }
    
      /* Wait to be interrupted by a signal.  */
      pause ();
      return 0;
    }
    

    If you see the parent hanging in waitpid, it means the child has not exited. Try to attach with a debugger to see where the child is blocked, or, easier, run the program with strace(1). How do you clean up your pid array? Make sure the children are not trying call waitpid with pid parameter being <= 0. Make sure the children are not blocking or ignoring the signal.

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

Sidebar

Related Questions

i have one problem controlling checkbox, i'm reading, and searching about the topic but
I have a problem as the topic name says: Lets say i have gallery
I post this topic because I have a problem with my iPhone application since
Hey I have a problem getting my head around how custom GWT event Handlers
I have a problem similar to this topic http://forums.asp.net/t/1763534.aspx/1 I have to show data
As suggested I'm asking new question in new topic. I have a problem with
I have got an issue with problem named in topic. I am trying to
I have this problem with Headers already sent with Magento. I get this error:
I've been working around a problem I have when using LINQ to Entities when
I have the same problem of this topic. but on the association between entities.

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.