Results 1 to 5 of 5
Hi!
I have a problem, I need to launch another binary from my application, but I need to get the control back once the other binary is initialized.
fork/exec doesn't ...
- 07-02-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 7
sort of execv command needed
Hi!
I have a problem, I need to launch another binary from my application, but I need to get the control back once the other binary is initialized.
fork/exec doesn't seem to give anything on that side
using pthreads I'm able to wait until the new thread exits, but that's not what I want
at the moment I'm using popen, but it doesn't seem to do the job right...
any help? what am I missing?
EDIT: ops... I wanted to make this post under "Linux Programming & Scripting" section... I think this actually make me a Linux Newbie
- 07-03-2010 #2
Moved it for you
.
As far as how to accomplish this, you were right on with the fork/exec combination. As you know, fork() will return in both the parent and child processes. You have the child do the exec() and launch the binary.
In the parent, you then use the waitpid() function with the child's PID (which is returned from fork()). This will cause the parent process to wait for the child to finish, at which point the parent will resume.
waitpid(2): wait for process to change state - Linux man pageDISTRO=Arch
Registered Linux User #388732
- 07-04-2010 #3Just Joined!
- Join Date
- Mar 2010
- Posts
- 7
hey!!
Thank you for the move
btw my problem is that I need the parent to wait until the child has done the exec (or whatever) and start BEFORE the binary finish...as I know the exec just replaces the process so the child finishes when the binary does...
I mean, my parent should work while the binary is executing, I know I'm not so clear in explanation let's say I have something like this: (just an example)
I need the parent to "wait" until the calculator binary start and when it's running, doing stuff with it... my problem is that I do not have the source of the binary, so I should make all the checks in my parent.Code:int main(int argc, char *argv[]){ char *child_args[] = {"/usr/bin/gcalctool", NULL}; int cpid = fork() if (cpid == 0){ execv(child_args[0],child_args); //perror } else if (cpid > 0){ //parent stuff that works with the calculator binary } else //perror and bla bla bla }
thank you!!!
- 07-04-2010 #4
Your problem seems to be more with synchronizing with the child, than of loading and launching it. I do not think there is any way of ensuring that that the child process is executing or has reached any particuar point of execution without using some form of Interprocess Communication (IPC). Since you say that the launched binary is a black box to you, without known hooks to accomplish this, you will have to make some assumptions or find a way of communicating with it. If the child uses standard IO to convey it's work, you have the option of setting up a pipe to capture it's output in your parent process, and this may allow you to achieve your goal.
--- rod.Stuff happens. Then stays happened.
- 07-04-2010 #5Just Joined!
- Join Date
- Mar 2010
- Posts
- 7
thank you, I'll try that way


Reply With Quote