I want to create copies of a process using fork() in C.
I cant figure out how to pass arguments to the copies of my process.
For example,I want to pass an integer to the process copies.
Or I what to do, if I have a loop in which I call fork() and want to pass a unique value to processes (e.g. 0…N)
for (int i = 0; i < 4; ++i) {
fork();
// pass a unique value to new processes.
}
The nice part about
fork()is that each process you spawn automatically gets a copy of everything the parent has, so for example, let’s say we want to pass an intmyvarto each of two child processes but I want each to have a different value from the parent process:So doing this allows each process to have a “copy” of
myvarwith it’s own value.If you didn’t change the value, then each fork’d process would have the same value.