I have a program that have many threads. Some threads are TCP servers... Each server fires new threads to handle any new connections.
Inside one of the threads that handles a single client, I call fork(). The child process calls setpgid() (to create a new group) and then system() (the function of C/C++ standard library). The parent process keeps taking naps (usleep() function) and checking a time limit. If the time limit is exceeded before child process returns from system(), the parent SIGKILLs the child.
I'm using: Linux (Ubuntu), pthreads, etc. Nothing but C/C++ standard library!
My questions: what happens with all the threads and TCP sockets on the child process? Are these things inherited from the parent process? Will both child and parent run all these threads and TCP servers simultaneously? It would make no sense to me... And when parent SIGKILLs child, will the sockets be closed only inside child, or also in the parent?
Currently, I'm actually using exec() to clean the whole image of the child process, but I'd rather call system() directly if it's safe.