I'm writing a program using children processes in C. Basically, the children reads distinct files and calculates a summation. Then they need to return it to main process. How can I return from them to main process?
Asked
Active
Viewed 28 times
0
-
1[Trying to implement piping in C - shell is hanging and not running commands](https://stackoverflow.com/q/54602168/3422102)? Secret - search `"[c] execvp pipe fork corpse"` in the search box above -- take your pick (it elicits helpful answers from a very knowledgeable source, the `"corpse"` being unique to one JLF). – David C. Rankin Nov 10 '21 at 08:20
-
`exit(result)` in child. `waitpid(pid,&status,0) ` trick would work. but only for int value. `status` will hold result – Tauqeer Akhtar Nov 10 '21 at 08:24
-
Note that you can only return values in the range 0..255 via the exit status. That is usually inadequate. – Jonathan Leffler Nov 10 '21 at 08:27
-
You can use shared memory `(shm_open(), shm_unlink(), mmap(), etc.).` . – Tauqeer Akhtar Nov 10 '21 at 08:31