[Insight-developers] Using kwsys/Process.h functions
Brad King
brad.king at kitware.com
Fri May 4 15:49:46 EDT 2007
kent williams wrote:
> I just wrote some code to do coarse-grained parallelism using the
> kwsysProcess functions. I run two external programs at the same time on a
> multiprocessor.
>
> It worked as advertised except for one thing: If I ran a process
> synchronously -- i.e. I didn't set kwsysProcess_Option_Detach -- and then
> called kwsysProcess_GetExitValue, the exit code returned was always 1, even
> if the program successfully executed.
>
> If I ran the program detached, the correct exit code was returned.
>
> My work around was to run all processes detached, but call
> kwsysProcess_GetExitValue to block and wait for the process synchronously if
> needed.
>
> Since kwsysProcess is used in Cmake, I assume it has been thoroughly tested,
> and I'm just missing something. Am I?
It's used not just by CMake, but also by CTest to run every test on all
the dashboard machines. It's pretty well tested :)
Are you calling kwsysProcess_WaitForExit before getting the result?
Here is typical usage:
kwsysProcess* kp = kwsysProcess_New();
kwsysProcess_SetCommand(kp, cmd);
kwsysProcess_Execute(kp);
kwsysProcess_WaitForExit(kp, 0);
switch(kwsysProcess_GetState(kp))
{
case kwsysProcess_State_Exited:
{
int retVal = kwsysProcess_GetExitValue(kp);
} break;
/* ... handle other cases ... */
}
kwsysProcess_Delete(kp);
FYI, once the process is detatched you cannot get the exit value because
the structure has dropped all references to the child. It's meant for
starting daemons.
-Brad
More information about the Insight-developers
mailing list