P
pwu
I'm starting a C program from Java via the exec method. The C program
forks off a child and execvp another program over the child process.
The parent process exits after printing out the process pid.
The Java program does a waitFor. However the waitFor waits for both the
main C program AND the child. I only want to wait for the main C
program
only.
The Java program:
// Get our runtime
me=Runtime.getRuntime();
command=launcher + " /bin/ksh " + editedwrapper;
newproc=me.exec(command);
pin = new BufferedReader(new
InputStreamReader(newproc.getInputStream()));
// Echo back what the program spit out
while ((pline=pin.readLine())!=null)
{
System.out.println(pline);
}
newproc.waitFor();
status=newproc.exitValue();
The C program forks off a new process as follows:
/* Create the new process which is a copy of this process */
if ((pid=fork()) < 0)
{
exit(-1);
};
/* The child process: */
if (pid == 0)
{
if (execvp(argv[1], newarglist) < 0) /* execute the command */
{
exit(-1);
}
/* Child goes not proceed past here */
}
/* Parent */
exit(0);
The java waitFor waits for BOTH the exec'ed process and the child. I
want
java to wait for the exec'ed process but not the child.
How do I do this?
forks off a child and execvp another program over the child process.
The parent process exits after printing out the process pid.
The Java program does a waitFor. However the waitFor waits for both the
main C program AND the child. I only want to wait for the main C
program
only.
The Java program:
// Get our runtime
me=Runtime.getRuntime();
command=launcher + " /bin/ksh " + editedwrapper;
newproc=me.exec(command);
pin = new BufferedReader(new
InputStreamReader(newproc.getInputStream()));
// Echo back what the program spit out
while ((pline=pin.readLine())!=null)
{
System.out.println(pline);
}
newproc.waitFor();
status=newproc.exitValue();
The C program forks off a new process as follows:
/* Create the new process which is a copy of this process */
if ((pid=fork()) < 0)
{
exit(-1);
};
/* The child process: */
if (pid == 0)
{
if (execvp(argv[1], newarglist) < 0) /* execute the command */
{
exit(-1);
}
/* Child goes not proceed past here */
}
/* Parent */
exit(0);
The java waitFor waits for BOTH the exec'ed process and the child. I
want
java to wait for the exec'ed process but not the child.
How do I do this?