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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:50:42+00:00 2026-05-27T09:50:42+00:00

I want to understand the following code well: /* Become deamon + unstoppable and

  • 0

I want to understand the following code well:

/* Become deamon + unstoppable and no zombies children (= no wait()) */

if(fork() != 0)  return 0;        /* Parent returns OK to shell */
signal(SIGCLD, SIG_IGN);          /* ignore child death */
signal(SIGHUP, SIG_IGN);          /* ignore terminal hangups */
for(i = 0; i < 32; i++) close(i); /* close open files */
setpgrp();                        /* break away from process group */

Here is how I understand the above code:

1st line: Creating a child process and terminating the parent process, so the parent parent process will go back to the shell and the child process will continue executing the program in background.

2nd line: Ignore the signal that is supposed to be sent to the parent process (who’s controlling the terminal) when the child process (who’s executing the program) is terminated. I think this line will avoid the occurrence of zombies children?

3rd line: I read that it ignores POSIX’s Hangup and I am not sure what it is exactly.

4th line: closing the open files whose descriptor files are 0 to 31 (I am not sure why from 0 to 31)

5th line: No idea what it does.


Can you please help me to understand this code well? Thanks 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-27T09:50:43+00:00Added an answer on May 27, 2026 at 9:50 am

    1) fork()’ing and returning in the parent, has two meanings: A) Run in the background. B) Avoid zombies in a portable way

    2) http://en.wikipedia.org/wiki/SIGCHLD

    3) SIGHUP is often delivered to a process when a tty is closing. It more or less means “Continue running, even if the associated tty goes away”.

    4) Closing file descriptors allows starting a daemon from something like an ssh session, without the ssh session waiting around on close for the filedescriptors 0-31 to be closed. If you don’t do this, daemons may sometimes cause ssh sessions to seem to hang on exit. There’s nothing magic about 0-31 – some processes close more file descriptors than that, but of course 0, 1 and 2 have special meanings: stdin, stdout, stderr respectively.

    5) http://en.wikipedia.org/wiki/Process_group

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

Sidebar

Related Questions

I want to understand why the following is happening. My guess is that a
I want to understand if code snippets are what I am looking for here.
I want to understand the use of xargs man in Rampion's code : screen
I dont understand why the following code is not working. I save some inputs
The following code (which compiles and executes properly, doing what I want) is a
Converting a value to a colour is well known, I do understand the following
I am trying to understand how the following code ties into two other .java
I want to understand the external linkage and internal linkage and their difference. I
I want to understand how a C++ program that was given to me works,
I want to understand how the mechanism of Shadowing and Nested function work. For

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.