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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:34:07+00:00 2026-06-10T17:34:07+00:00

Consider this snippet of code: void do_child(void); int main(void){ int n; pid_t child; printf(Write

  • 0

Consider this snippet of code:

void do_child(void);

int main(void){
int n;
pid_t child;
printf("Write a number: ");
scanf("%d", &n);
if(n != 1){
exit(1);
}
child = fork();
if(child >= 0){ /* fork ok */
 if(child == 0){
    printf("Child pid: %d\n", getpid());
    do_child();
    _exit(0);
  }
 else{ /* parent */
    printf("Child parent: %d\n", getpid());
    _exit(0);
 }
}
else{ /* fallito */
    perror("No fork");
    return 1;
}
return EXIT_SUCCESS;
}

void do_child(void){
/* some code here */
if(1 != 1){
    /* what to write here?? _exit or exit*/
}   
}

When exiting from a child process it is best to write _exit instead of exit but if i need to call an external function and into this function i want to put an exit, what should i write? _exit or exit?

  • 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-06-10T17:34:09+00:00Added an answer on June 10, 2026 at 5:34 pm

    You can expect exit to call functions registered with atexit. _exit won’t do that. Normally, each registered cleanup handler should be executed exactly once, usually in the process in which it was registered. This means that a child process should _exit() and the parent should exit(). If the child process does exec some other program, which is probably the most common case, then that new program will overwrite any registered handlers, which means that you are back to exit().

    As to external functions: I’d say you should call exit but you should be prepared to encounter strange behaviour if the parent registers non-trivial stuff atexit before doing the fork. So try to fork early unless you mean to exec in the child. And have an eye on what exit handlers your own code and the libraries you use might install. I/O buffer flushing is one example.

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

Sidebar

Related Questions

Consider this code snippet: public static void main(String[] args) { int z1 = 0;
Consider this code snippet: class Program { static void Main(string[] args) { Console.WriteLine(Test().ToString()); }
consider this code snippet void make(int n) { std::string user_input; std::istringstream iss(user_input); char letter;
Let’s consider this very short snippet of code: #include <stdlib.h> int main() { char*
Let's consider the following code snippet void Test() { int x = 0; int&
Consider this code snippet public class ConstantFolding { static final int number1 = 5;
Consider this code snippet: pid_t cpid = fork(); if (cpid == -1) { perror(fork);
Consider the following code-snippet typedef int type; int main() { type *type; // why
Consider this snippet of code: Func<int, bool> TestGreaterThanOne = delegate(int a) { if (a
Please consider this code snippet: private static void doSomething(Double avg, Double min, Double sd)

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.