- Spawn a new process for each instance of that graph generating thing you are doing;
- In the parent process, keep an hash, push child’s process id there as key, and the connection as value.
- The parent process periodically checks each child process in that table.
- If the connection for a child is aborted, kill the child process, and remove the record from hash
- also check whether the child process completed, if yes, remove the record from the hash.
Personally, I would also push the start time of each child in the hash, so that I can check the elapsed time for each child process, and the parent process may kill the child process after an arbitrary time (your program has to prepare for the worst, what if the child process is just hanging?)