Thread: Father and Son Variables

  1. #1
    Registered User khdani's Avatar
    Join Date
    Oct 2007
    Posts
    42

    Father and Son Variables

    Hello,
    When creating son process with fork(), does it have its own copy of function's local variables? I mean if I change local variable of a function where son was created, will the father see the change or they have different copies of the variables? What about global variables or pointers to variables ?
    Thank you

  2. #2

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by khdani View Post
    Hello,
    When creating son process with fork(), does it have its own copy of function's local variables? I mean if I change local variable of a function where son was created, will the father see the change or they have different copies of the variables? What about global variables or pointers to variables ?
    Thank you
    Yes, the child has it's own copy. No, the parent does not see what happens to it and vice versa. This includes global variables, etc. They are running as seperate processes, the same as if at fork() you you had instantiated two programs.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User khdani's Avatar
    Join Date
    Oct 2007
    Posts
    42
    Thank You MK27 and C_ntua

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple problem with classes
    By desdelaspalmas in forum C++ Programming
    Replies: 3
    Last Post: 12-01-2008, 03:15 AM
  2. Simple Processes Program
    By khdani in forum Linux Programming
    Replies: 9
    Last Post: 11-18-2008, 10:59 AM
  3. managing father and son processes
    By Andreak in forum C Programming
    Replies: 4
    Last Post: 06-03-2005, 09:50 AM
  4. Religion
    By gnu-ehacks in forum A Brief History of Cprogramming.com
    Replies: 239
    Last Post: 01-26-2002, 10:44 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM