MCPcopy Create free account
hub / github.com/Kitware/CMake / kwsysProcessFork

Function kwsysProcessFork

Source/kwsys/ProcessUNIX.c:2453–2496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2451
2452#if !defined(__VMS)
2453static pid_t kwsysProcessFork(kwsysProcess* cp,
2454 kwsysProcessCreateInformation* si)
2455{
2456 /* Create a detached process if requested. */
2457 if (cp->OptionDetach) {
2458 /* Create an intermediate process. */
2459 pid_t middle_pid = fork();
2460 if (middle_pid < 0) {
2461 /* Fork failed. Return as if we were not detaching. */
2462 return middle_pid;
2463 }
2464 if (middle_pid == 0) {
2465 /* This is the intermediate process. Create the real child. */
2466 pid_t child_pid = fork();
2467 if (child_pid == 0) {
2468 /* This is the real child process. There is nothing to do here. */
2469 return 0;
2470 }
2471 /* Use the error pipe to report the pid to the real parent. */
2472 while ((write(si->ErrorPipe[1], &child_pid, sizeof(child_pid)) < 0) &&
2473 (errno == EINTR)) {
2474 }
2475
2476 /* Exit without cleanup. The parent holds all resources. */
2477 kwsysProcessExit();
2478 return 0; /* Never reached, but avoids SunCC warning. */
2479 }
2480 /* This is the original parent process. The intermediate
2481 process will use the error pipe to report the pid of the
2482 detached child. */
2483 pid_t child_pid;
2484 int status;
2485 while ((read(si->ErrorPipe[0], &child_pid, sizeof(child_pid)) < 0) &&
2486 (errno == EINTR)) {
2487 }
2488
2489 /* Wait for the intermediate process to exit and clean it up. */
2490 while ((waitpid(middle_pid, &status, 0) < 0) && (errno == EINTR)) {
2491 }
2492 return child_pid;
2493 }
2494 /* Not creating a detached process. Use normal fork. */
2495 return fork();
2496}
2497#endif
2498
2499/* We try to obtain process information by invoking the ps command.

Callers 1

kwsysProcessCreateFunction · 0.85

Calls 3

writeFunction · 0.85
kwsysProcessExitFunction · 0.85
readFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…