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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:54:41+00:00 2026-06-03T22:54:41+00:00

I am using fork in my code. Before fork call in my code, the

  • 0

I am using fork in my code. Before fork call in my code, the parent process has a global variable declared. So after the fork call does child process get a separate copy of the global variable on its own thread stack or shares the existing parent instance of global variable. so i guess there are three possibilities here
1) child process gets separate instance of global variable declared in parent process
2) child process shares the global variable with parent thread. (which is possibly not true)
3) child process doesnt have any sought of information about the global variable in parent thread

If either 2 or 3 options are true, i want to know if there is any way of getting the global variable and its “state/value at time of execution of fork()” declared in parent thread, in child process.

so broadly, is there any way of accessing parent processes variable and there states in child process created using 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-06-03T22:54:44+00:00Added an answer on June 3, 2026 at 10:54 pm

    Each process has its own memory space. A process can’t normally access another process’s memory.

    In the case of fork, the child process’s memory space starts as an exact copy of the parents. That includes variables, code, etc. Changing any of these in one will not change any similar variable in the other.

    So it’s answer #1.


    Even if you could, the question you should be asking isn’t “how do I share variable?” but “how do I exchange data?”. Having a controlled channel is less error-prone as it provides looser coupling and less action-at-a-distance.

    Pipes are often use to communicate between parent and child, but there are many other options.

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

Sidebar

Related Questions

I have created a parent and a child process using fork( ), and both
How does the Child process generate using Fork() function. For example: A process execute
I have created two processes using fork(). The child process is producing and writing
My issue is related to using fork() within Perl code. I wish to fork
I'm trying to write a daemon process using code igniter library, and the problem
I'm trying to spawn a new process from my C++-project using fork-exec. I'm using
The following code sends messages from child processes to their parents using socket pairs.
I'm using fork() on Perl on Windows (ActivePerl) for a basic socket server, but
I'm using Telligent's RSS.Net fork to parse an XML Stream. The stream is well-formed
I'm trying to clone my personal fork on github using the git+ssh protocol with

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.