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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:49:14+00:00 2026-05-13T15:49:14+00:00

I know what the fork() does at the higher level. What I’d like to

  • 0

I know what the fork() does at the higher level. What I’d like to know is this –

  1. As soon as there is a fork call, a trap instruction follows and control jumps to execute the fork “handler” . Now,How does this handler , which creates the child process, by duplicating the parent process by creating another address space and process control block , return 2 values, one to each process ?

  2. At what point of execution does the fork return 2 values ?

To put it in short, can anbody please explain the step-by-step events that take place at the lower level after a fork call ?

  • 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-13T15:49:14+00:00Added an answer on May 13, 2026 at 3:49 pm

    It’s not so hard right – the kernel half of the fork() syscall can tell the difference between the two processes via the Process Control Block as you mentioned, but you don’t even need to do that. So the pseudocode looks like:

    int fork()
    {
        int orig_pid = getpid();
    
        int new_pid = kernel_do_fork();     // Now there's two processes
    
        // Remember, orig_pid is the same in both procs
        if (orig_pid == getpid()) {
            return new_pid;
        }
    
        // Must be the child
        return 0;
    }
    

    Edit:
    The naive version does just as you describe – it creates a new process context, copies all of the associated thread contexts, copies all of the pages and file mappings, and the new process is put into the “ready to run” list.

    I think the part you’re getting confused on is, that when these processes resume (i.e. when the parent returns from kernel_do_fork, and the child is scheduled for the first time), it starts in the middle of the function (i.e. executing that first ‘if’). It’s an exact copy – both processes will execute the 2nd half of the function.

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

Sidebar

Related Questions

Know of any good libraries for this? I did some searches and didn't come
I know that I can do something like $int = (int)99; //(int) has a
I know this might be a no-brainer, but please read on. I also know
I know there is a registry key indicating the install directory, but I don't
I know I must be missing something, but in a while statement how does
I don't know haskell syntax, but I know some FP concepts (like algebraic data
I know that fork() returns differently for the child and parent processes, but I'm
I have a Perl script that does a fork/exec to start another tool in
I dont understand why my code does not work. This is my code. I
I'm trying to fork 3 different child processes from a parent (and running this

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.