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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:47:43+00:00 2026-05-27T22:47:43+00:00

#include <stdio.h> #include <unistd.h> int main() { fork(); fork() && fork() || fork(); fork();

  • 0
    #include <stdio.h>
    #include <unistd.h>
    int main()
    {
       fork();
       fork() && fork() || fork();
       fork();

     printf("forked\n");
     return 0;
    }

It cause difficulty to understand how to calculate number of processes spawned after executing the program?
Help me to find out.

Platform –UBUNTU 10.04

  • 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-27T22:47:43+00:00Added an answer on May 27, 2026 at 10:47 pm

    Let’s follow the fork-tree, assuming none of the forks fails

    fork();

    Now we have two processes, so far it doesn’t matter who’s child and who parent, call them p1 and p2

    fork()

    Both of those processes spawn another child, so we have 4 processes, for two of them (p3, p4) the result is zero, for the other two (p1 and p2) it’s nonzero

       && fork()
    

    p1 and p2 fork again, giving p5 and p6, six processes total. In p1 and p2, the && evaluates to true, so they don’t fork again in this line. For p3, p4, p5, p6, the && evaluates to false, so they fork

                  || fork();
    

    here, spawning four new processes, giving a total of 6 + 4 = 10.

    fork();

    each of the 10 processes forks again, makes 20.

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

Sidebar

Related Questions

#include<stdio.h> #include<zlib.h> #include<unistd.h> #include<string.h> int main(int argc, char *argv[]) { char *path=NULL; size_t size;
#include<stdio.h> #include<time.h> int main() { clock_t start; double d; long int n,i,j; scanf(%ld,&n); n=100000;
#include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int i =10;
#include <unistd.h> #include <stdio.h> int main() { char buff[100]; int pfd[2]; buff[0] = '\0';
#include <unistd.h> #include <stdio.h> int main(int argc, char* argv[]) { int f1[2], f2[2]; char
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);
I was trying to understand forks, and tried following in C: #include<stdio.h> #include <unistd.h>
#include<stdio.h> #include<unistd.h> #include<stdlib.h> #include<sys/ipc.h> #include<sys/msg.h> #include<sys/types.h> struct mbuffer{ long mtype; int mtext; }stResult; int
Here is my code for fork() system call, #include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<sys/stat.h> #include<unistd.h> #include<errno.h>

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.