in reply to killing command if it takes too much time

As you have it right now, you're stopping execution of your program while the command executes because of the backticks. You want them both to happen at the same time, and to me that suggests either threads or fork; I'd personally use fork, but that's because I know the model better.

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.

  • Comment on Re: killing command if it takes too much time