C++: Timeout for an external application call -


for c++ program i'm working on, have call external application operations. can't modify application. operations may take time have add timeout. tried using system() , boost threads

int main()  {   [...]    boost::thread t(function1);   t.timed_join(boost::posix_time::seconds(10));    [...]    return 0; }  void function1() {   system("external application"); } 

but when return main 10 seconds later, external application still running in background. using exec() instead of system() nothing works because "lose" main. can do? i'm on linux.

use fork(2), execve(2), waitpid(2) instead of system (which internally uses these syscalls). read advanced linux programming explains tricky details.

you want use setrlimit(2) in child. or in parent kill(2) child (first sigterm, sigkill) on timeout.

you may want child make own process group using setpgid(2) or setpgrp, kill entire process group killpg(2). kill both child , command has started (unless these create there own process groups themselves).

you handle sigchld signal (see signal(7)) using sigaction(2). sigchld notably sent when child process terminates.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -