in reply to killing command if it takes too much time
Outlining this vaguely, I'd fork off the command, using a socketpair to communicate back to the main program. The main program could use select to simultaneously sleep a while and check for any output from the forked command. If it didn't find any after an appropriate delay, it could then kill the forked-off command and take whatever recovery actions were necessary. If it was getting output and decided to let the command continue, or the command completed, then it would simply read input from the socket while select said there was input available, and either go back to sleep, waiting for more input, or read to EOF then close the socket and waitpid on the PID returned by the fork.
|
|---|