jackyjung 2012. 1. 18. 10:20

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>

int global = 10;

int main() {
    int local = 5;
    pid_t pid;

    if ((pid = fork()) == 0) {
        global++; local++;
    } else {
        sleep(1);
    }
    printf("pid : %d, global:%d, local: %d\n", getpid(), global, local);
    return 0 ;
}

child process share the memory space of parent. when the write operation is occurred, the child copy memory space of parent.              
root@jcjung:/work# ./fork_test 
pid : 2018, global:11, local: 6
pid : 2017, global:10, local: 5