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.
, .
. (, , , , ). , , . UNIX fork(), . (shmget, smctl), fork.
fork()
shmget
smctl
forking , , API, . , , fork , . , fork() ( fork + parent) (pipe + fork + exec), popen().
popen()
C API- pthreads , . , , fork, , , fork , .
fork, . . , , ..
. Linux , " ". , . , , , . , , , fork .