View Full Version : [SOLVED] How can one execute an external program without waiting for it to finish?
TheHimself
January 13th, 2011, 10:54 PM
When I use system() or popen() my program halts until the external one is finished but I don't want that. I'd also like the external program to continue even if my program is closed.
sharathcshekhar
January 13th, 2011, 11:06 PM
You have to make your program run in multi threads/Process.. There is no other way to make a non blocking system call..
rnerwein
January 15th, 2011, 04:01 PM
When I use system() or popen() my program halts until the external one is finished but I don't want that. I'd also like the external program to continue even if my program is closed.
hi
it looks like you are programming C languge.
then you can do ( what even servers do and get rid of child procs - no zombies ) then uses any kind of
exec:
fork -> fork -> exec ( have a look of "man exec" ).
hint: if you use popen --> don't forget pclose or you will get zombie processes because pclose will be mayde
the embedded wait for you.
ciao
p.s. C is lake a razor but without a grip
sorry this one of the first try and the ubuntu server told me ---> fault :-)
dwhitney67
January 15th, 2011, 04:18 PM
When I use system() or popen() my program halts until the external one is finished but I don't want that. I'd also like the external program to continue even if my program is closed.
Run the external program in the background. For example:
system("/path/to/external_program &");
Similarly with popen() you can run a program in the background, but this seems fishy/silly.
FILE* pd = popen("/path/to/external_program &", "r");
...
pclose(pd);
TheHimself
January 24th, 2011, 04:05 PM
Re dwhitney67, what does the operator & do exactly?
Arndt
January 24th, 2011, 04:17 PM
Re dwhitney67, what does the operator & do exactly?
From the bash manual page:
"If a command is terminated by the control operator &, the shell exe‐
cutes the command in the background in a subshell. The shell does not
wait for the command to finish, and the return status is 0."
TheHimself
January 31st, 2011, 07:37 PM
Thanks dwhitney67 and Arndt!
:guitar:
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.