[Insight-developers] Using kwsys/Process.h functions
kent williams
norman-k-williams at uiowa.edu
Fri May 4 16:51:46 EDT 2007
I see what you intend here. I was confused by the concept of
kwsysProcessDetach -- I thought that you had to set detach in order for it
to run concurrently. Is it the case that the processes started are always
running concurrently, but if they're detached it drops all attachment to the
process?
What I want to do is pretty simple: If I'm on a multiprocessor machine,
start more than one instance of an external program in parallel.
On 5/4/07 2:49 PM, "Brad King" <brad.king at kitware.com> wrote:
> 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
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
More information about the Insight-developers
mailing list