I'm a student working on a Unix socket/network programming project in C/C++. I'm writing a simple server that can receive TCP messages from multiple clients. Following this guide I've written the server to accept() incoming client connections and then fork() to deal with sending some messages back/forth to each client. So far it's all been pretty easy.
Now, I need to take the data gathered in each fork()-ed child process, pass it back to the parent process that did the accept()-ing, and allow the parent to continue running with the collected data and let each child return 0;. (1 process -> many processes collecting data -> 1 process with all data)
I don't know the best way to do this. My course teaches networking, not managing processes in Unix. How do child processes send data back to the parent? Or, can they somehow share data among themselves? Or, am I approaching this the wrong way entirely?
pthread_createto launch a function to handle each client connection accepted, then you can easily have the threads generate their data and tell the main accepting thread about it (that thread could collectvoid*s to the data, as that's the "result" type returned by exiting threads as their control threadpthread_joins them.).