Using fork: access to process child memory from parent

I use fork () in C to separate the work of working with local arrays, each of which goes through half, and then multiplies the numbers at each point of the arrays and then sets the product in the third array.

pid_t  pid;
pid = fork();

if (pid == 0){
    for (i=1; i<((SIZE/2)+1); i++)
    {
        output[i] = (one[i] * two[i]);
    }
    exit(0);
}
else{
    wait(NULL);
        for (i=((SIZE/2)+1); i<(SIZE+1); i++)
        {
            output[i] = one[i]*two[i];
        }         
}

However, when I print an array of products after this code segment, I only get the section specified by the parent process, I assume that this is because the child process stores its values ​​in a different place in memory, the parent of which was unable to pick up when printing the array products, but I'm not quite sure. Thanks in advance for any help.

+4
source share
2

, .

. (, , , , ). , , . UNIX fork(), . (shmget, smctl), fork.

forking , , API, . , , fork , . , fork() ( fork + parent) (pipe + fork + exec), popen().

C API- pthreads , . , , fork, , , fork , .

+5

fork, . . , , ..

. Linux , " ". , . , , , . , , , fork .

+3

All Articles