# Possible race condition in ProcessUNIX process creation

**URL:** https://discourse.cmake.org/t/possible-race-condition-in-processunix-process-creation/15815
**Category:** Development
**Created:** [August 31, 2026, 3:47am UTC](https://discourse.cmake.org/t/possible-race-condition-in-processunix-process-creation/15815 "2026-08-31T03:47:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Oskari\_Alaranta](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/8e8cbc/32.png) [@Oskari\_Alaranta](https://discourse.cmake.org/u/Oskari_Alaranta)
#### Post date: [August 31, 2026, 3:47am UTC](https://discourse.cmake.org/t/possible-race-condition-in-processunix-process-creation/15815/1 "2026-08-31T03:47:03Z")

</div>

When creating a process in `kwsysProcessCreate`, we create a `pgidPipe` which gets closed when the child does the `execvp` call. After fork, parent reads the `pgidPipe` until it returns EOF or an error. There is a race condition if the parent’s blocking read call wakes up only after the child has already exited, leading to SIGCHLD and read returning -1 with EINTR. Linux probably does handle this and makes sure EOF is reported before EINTR but POSIX makes no such guarantees. I was digging around as my OS’s cmake port was failing to do any quick child invocations. The fix would be to either block SIGCHILD in addition to SIGINT and SIGTERM at the start, or handle EINTR return from `pgidPipe` read. I attached a patch with latter fix.

> **(attachments)**
>
> [0001-ProcessUNIX-Fix-possible-race-condition.patch](https://discourse.cmake.org/uploads/short-url/2ux7bdDMu0NJEoDeJqUdVG831ct.patch) (997 Bytes)

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [August 31, 2026, 1:19pm UTC](https://discourse.cmake.org/t/possible-race-condition-in-processunix-process-creation/15815/2 "2026-08-31T13:19:39Z")

</div>

Thanks for the analysis and patch. I’ve opened [KWSys MR 381](https://gitlab.kitware.com/utils/kwsys/-/merge_requests/381) to apply the patch. Once merged I’ll update CMake’s copy.

However, note that CMake no longer uses KWSys’s Process implementation to launch child processes. We’ve used libuv since CMake 3.29 or so for everything except the legacy `exec_program` command, long superseded by `execute_process`.
