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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:52:35+00:00 2026-05-29T07:52:35+00:00

Looking to fork a process, in c++, that wont hang its parent process –

  • 0

Looking to fork a process, in c++, that wont hang its parent process – its parent is a daemon and must remain running. If i wait() on the forked process the forked execl wont defunt – but – it will also hang the app – not waiting fixes the app hang – but the command becomes defunt.

if((pid = fork()) < 0)
    perror("Error with Fork()");
else if(pid > 0) { 
    //wait here will hang the execl in the parent
    //dont wait will defunt the execl command 
    //---- wait(&pid);
    return "";
} else {
    struct rlimit       rl;
    int                 i;

    if (rl.rlim_max == RLIM_INFINITY)
        rl.rlim_max = 1024;

    for (i = 0; (unsigned) i < rl.rlim_max; i++)
        close(i);

    if(execl("/bin/bash", "/bin/bash", "-c", "whoami", (char*) 0) < 0) perror("execl()");
    exit(0);
}

How can I fork the execl without a wait(&pid) where execl’s command wont defunct?

UPDATE
Fixed by adding the following before the fork

signal(SIGCHLD, SIG_IGN);

Still working with my limited skills at a more compatible solution based on the accepted answer. Thanks!

  • 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-29T07:52:35+00:00Added an answer on May 29, 2026 at 7:52 am

    By default, wait and friends wait until a process has exited, then reap it. You can call waitpid with the WNOHANG to return immediately if no child has exited.

    The defunct/”zombie” process will sit around until you wait on it. So if you run it in the background, you must arrange to reap it eventually by any of several ways:

    • try waitpid with WNOHANG routinely: int pid = waitpid(-1, &status, WNOHANG)
    • install a signal handler for SIGCHLD to be notified when it exits

    Additionally, under POSIX.1-2001, you can use sigaction set the SA_NOCLDWAIT on SIGCHLD. Or set its action to SIG_IGN. Older systems (including Linux 2.4.x, but not 2.6.x or 3.x) don’t support this.

    Check your system manpages, or alternative the wait in the Single Unix Specification. The Single Unix Spec also gives some helpful code examples. SA_NOCLDWAIT is documented in sigaction.

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

Sidebar

Related Questions

Looking for an example that: Launches an EXE Waits for the EXE to finish.
Looking at what's running and nothing jumps out. Thanks!
Looking for a Linux application (or Firefox extension) that will allow me to scrape
Moose is a fantastic object framework. The trouble is that, taken together with its
I'm looking for well organized information sources about how the upcoming jsr166y (fork-join, fences)
I'm having trouble forking a long-running process from some code running under mod_perl2. Everything
I have a PHP script running as a daemon. Every once in a while,
I'm looking for a javascript library that attempts to provide the same simple utilities
I want to use gdb for looking into the various details of the fork()
I'm looking at pulling mustache.js into a project, and a quick glance at its

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.