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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:29:49+00:00 2026-05-31T09:29:49+00:00

The child process begins executing at the exact point where the last one left

  • 0

The child process begins executing at the exact point where the last one left off – after the fork statement. What if the statement contains multiple fork()s like the conditional expression like the following. Where exactly program execution starts for the child process. Before worrying about how many processes gets created, I wanted to know if every child process created tries to evaluate fork() && fork() || fork(); statement. If it is so. How does a child process that got created because of second fork() statement have information from the first fork() to evaluate fork() && fork().

main(){
fork() && fork() || fork();
}
  • 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-31T09:29:50+00:00Added an answer on May 31, 2026 at 9:29 am

    The child that results from the second fork() knows about the results of the first fork() because it is an exact copy of the parent process.

    You can work out what happens by drawing a little tree for yourself. Start with the first fork:

             fork()
               /\
              /  \
    parent --/    \-- child1
    

    The parent gets back the PID of the child1 process, and child1 gets back 0. So we have something like:

    PID(child1) && fork() || fork()
    

    in the parent, and:

    0 && fork() || fork()
    

    in the child. Short circuiting means that the middle fork() of the original expression doesn’t get executed in the child, only in the parent. So now what happens to the tree?

                      fork()
                        /\
                       /  \
             parent --/    \-- child1
             fork()
               /\
              /  \
    parent --/    \-- child2
    

    parent is the original process, and gets the PID of child2. child2, just like child1, gets 0. What do our expressions look like now?

    parent:  PID(child1) && PID(child2) || fork() = 1 || fork()
    child:   0 || fork()
    child2:  PID(child1) && 0 || fork() = 0 || fork()
    

    Now, again by short-circuiting, parent is done, and doesn’t execute the last fork(). Both child and child2 have to, however. That leaves us with the following tree:

                         fork()
                           /\
                          /  \
                parent --/    \-- child1
                fork()            fork()
                  /\                /\
                 /  \              /  \
                /    \   child1 --/    \-- child1-1
               /      \
              /        \
    parent --/          \-- child2
                            fork()
                              /\
                             /  \
                   child2 --/    \-- child2-1
    

    And that’s it. child1 and child2 each get the PID of their respective children, and child1-1 and child2-1 each get back 0. Substituting those values in, the final expressions are:

    parent:   1
    child1:   0 || PID(child1-1) = 1
    child2:   0 || PID(child2-1) = 1
    child1-1: 0 || 0 = 0
    child2-1: 0 || 0 = 0
    

    And that’s it – they all exit.

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

Sidebar

Related Questions

When creating a child process in C++ using Windows API, one can allow inheritance
After creating a child process and exiting it immediately (_exit()), I want to perform
Suppose I have a process which spawns exactly one child process. Now when the
If I fork a child process, and the child process exits before the parent
My application ( main.exe ) is executing a Child process ( child.exe ) using
I have created a parent and a child process using fork( ), and both
I'm trying to give a child process (via fork() ) foreground access to the
I have a program that uses fork() to create a child process. I have
As I understood fork() creates a child process by copying the image of the
The aim of the program is to fork a new child process and execute

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.