# std: introduce posix_spawn as an alt to fork-exec · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/dd55b7294946cf1982815518422a007b19438d71)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: dd55b7294946cf1982815518422a007b19438d71

Requested commit: dd55b7294946cf1982815518422a007b19438d71

Commit: dd55b7294946cf1982815518422a007b19438d71

Tree: 1f5977cb9f3a9a66a9943791821f4247b742f663

Author: Jakub Konka

Committer: Jakub Konka

## Message

```
std: introduce posix_spawn as an alt to fork-exec

Currently, the new API will only be available on macOS with
the intention of adding more POSIX systems to it incrementally
(such as Linux, etc.).

Changes:
* add `posix_spawn` wrappers in a separate container in
  `os/posix_spawn.zig`
* rewrite `ChildProcess.spawnPosix` using `posix_spawn` targeting macOS
  as `ChildProcess.spawnMacos`
* introduce a `posix_spawn` specific `std.c.waitpid` wrapper which
  does return an error in case the child process failed to exec - this
  is required for any process that was spawned using `posix_spawn`
  mechanism as, by definition, the errors returned by `posix_spawn`
  routine cover only the `fork`-equivalent; `pre-exec()` and `exec()`
  steps are covered by a catch-all error `ECHILD` returned by `waitpid`
  on unsuccessful execution, e.g., no such file error, etc.

```

## Parents

- [49c0bb1f33044658909cae4351d931af497ee4e5](https://git.cafe/gitcafe/zig/commit/49c0bb1f33044658909cae4351d931af497ee4e5?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/dd55b7294946cf1982815518422a007b19438d71?format=markdown)
