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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:11:35+00:00 2026-05-15T02:11:35+00:00

we are programming a bash like shell in C but we have problems with

  • 0

we are programming a bash like shell in C but we have problems with the background processes.
The thing is that the father waits for the children process when there is no &, we have made a signal_handler for SIGCHLD which have a wait inside.

The main problem that we want to avoid is: the signal_handler executes always (with background and foreground processes), so if the signal_handler catches the SIGCHLD before the father process, the father’s wait has not children to wait for, so it returns a error.

We depend on who of them executes before, and we want that if there isn’t & the signal_handler wait doesn’t collect the children before the father does.

Any help could be of paramount importance. 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-15T02:11:36+00:00Added an answer on May 15, 2026 at 2:11 am

    Your question was a little bit unclear to me, but I will mention some things that I’ve thought about doing for similar situations.

    When you create a process you could temporarily block SIGCHLD and place a record of the child process (and how it is to be treated) into a table.

    child_table_node_t * node = malloc(sizeof(child_table_node_t) );
    // err check that
    child_table_node_init(node, type_of_child_stuff);
    
    sigset_t old, set;
    
    sigemptyset(&set);
    sigaddset(&set, SIGCHLD);
    sigprocmask(SIG_BLOCK, &set, &old);
    pid_t pid = fork();
    if (pid > 0) {
       node->pid = pid;
       add_to_table(alive_children, node);
       sigprocmask(SIG_SETMASK, &old, NULL);
       // other stuff
    } else {
       sigprocmask(SIG_SETMASK, &old, NULL);
       if (!pid) {
           // do child stuff
       } else {
           // do parent with no child stuff
       }
    }
    

    Your handle_sigchild can then look up children who die (or stop or whatever) in the table and do something for them. I suggest removing them from the alive_children table and putting them in a dead_children table in the signal handler when they die so that your application can more easily handle them and deallocate their memory. If you want to keep up with children being stopped as well as dying then that will get a little bit more complicated b/c you won’t want to remove them from the alive table. It might be easier to just traverse the table in the non-signal code to locate changed nodes. If that were the case you might be able to do that without blocking the signals except when you added or removed a node.

    Your application could then do actions specific to the child that died based on data stored in the table node for that process. If the child were in the foreground then it’s death (or stop action) would be to store the exit code in to the exit code variable and start taking commands from the terminal or script again. If the newly deceased child were a background process then you just record its exit code and report that to the terminal before the next time you print a command prompt (if you are in interactive mode).

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

Sidebar

Ask A Question

Stats

  • Questions 464k
  • Answers 464k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer the Spring MVC-Ajax sample app is a good start, it… May 16, 2026 at 1:09 am
  • Editorial Team
    Editorial Team added an answer Read the SVN book. It boils down to this: When… May 16, 2026 at 1:09 am
  • Editorial Team
    Editorial Team added an answer argv[0] is (to the extent possible) supposed to be something… May 16, 2026 at 1:09 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.