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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:02:46+00:00 2026-06-03T13:02:46+00:00

Iam programing in C language and trying to learn the concepts of forking a

  • 0

Iam programing in C language and trying to learn the concepts of forking a process , bt iam getting
confused with the output of the following program. So i need some explanation regarding this to proceed.

        int main() {
            pid_t pid;
 24         int status, died;
 25         switch(pid = fork()){
 26                 case -1: printf("Can't fork\n");
 27                          exit(-1);
 28                 
 29                 case 0 : printf(" Child is sleeping ...\n"); 
 30                          sleep(5); // this is the code the child runs
 31                          //exit(3); 
 32                          
 33                 default:
 34                          printf("Process : parent is waiting for child to exit\n");
 35                          died = wait(&status); // this is the code the parent runs 
 36                          printf("Child's process table cleared...\n");
 37         }
 38         return 0;
 39 }

The output of the above program is :

Process : parent is waiting for child to exit
Child is sleeping ...
Process : parent is waiting for child to exit
Child's process table cleared...
Child's process table cleared...

Here iam not getting why this “Child’s process table cleared…” is coming twice. Pls explain.

Platform : Linux , gcc compiler

  • 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-03T13:02:47+00:00Added an answer on June 3, 2026 at 1:02 pm

    There is no break in the child’s case statement and hence the child too executes the default statement

    You seem to have commented out exit(3). It would have been better if it were there.

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

Sidebar

Related Questions

I am getting start to socket use in C programming language. I am trying
I am trying to learn my first programming language. Unfortunately I picked the Iphone
I am trying to learn pure functional programming language like Haskell as I am
I am facing extreme difficulty digesting the concepts of assembly language programming. I am
as I am learning the Ruby language, I am getting closer to actual programming.
Iam new to c programming and needs some help. long *taskids[NUM_THREADS]; for(t=0; t<NUM_THREADS; t++)
I am a student with a mainly electronics background getting into programing. The more
I am trying to create a custom installer technology for some fun and generic
I am new to the C programming language and trying to improve by solving
I am trying to design the package and module system for a programming language

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.