[CMake] [Insight-developers] Using KWSys to execute a detached process (Linux)

Brad King brad.king at kitware.com
Wed May 11 17:53:58 EDT 2011


On 05/11/2011 05:22 PM, Daniel Blezek wrote:
> the detach code does not seem to be tested

It is built as a test in KWSys under CMake but is not run automatically.
I don't remember why, but I can run the test by hand and it passes:

 $ ./kwsysTestProcess 8
 Output on stdout before test 8.
 Output on stderr before test 8.
 Output on stderr before grandchild test.
 Output on stdout before grandchild test.
 Child was disowned.
 Output on stdout after grandchild test.
 Output on stderr after grandchild test.
 Output on stdout from grandchild before sleep.
 Output on stderr from grandchild before sleep.
 Child exited with value = 0
 Output on stdout after test 8.
 Output on stderr after test 8.

Note that the output "after grandchild" appears before the output
"from grandchild".  That means the grandchild's parent kept running.

>       itksysProcess_SetCommand ( process, StringCommandLine );
>       itksysProcess_SetOption ( process, itksysProcess_Option_Detach, 1 );
>       itksysProcess_Execute ( process );
>       std::cout << "Execute" << std::endl;

Note that you need to call itksysProcess_Disown() to really let go of
the daemon process.  The Execute() call should return immediately
whether or not the Detach option is set.

-Brad


More information about the CMake mailing list