Waiting for a Child Process to Finish

A parent can wait for a child process to finish and collect a result describing how it exited.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a second step
  2. Separate starting from success
  3. Distinguish launch success from completed work
  4. Coordinate reading and waiting when capturing output

Trace a second step

A launcher starts a report writer, then needs its finished output for packaging. Collect the child's result before starting a dependent step. Build step dependencies formalize this ordering.

Separate starting from success

Successfully constructing the process does not prove it completed the requested operation. It may later reject input or fail reading a file. Its exit status and outputs convey that later result.[1]

Distinguish launch success from completed work

A parent starts a child to rebuild an index. Receiving a process handle confirms the child was started under the API's rules. The index is ready only after the child finishes with the expected status and output. See testing artifact completion.

Launch → handle exists
While child runs → output may be partial
Wait → final status
Validate file or result before consumption

Coordinate reading and waiting when capturing output

If the child writes enough to fill a bounded pipe, waiting before draining it can stall both sides. Use the process library's supported way to do both. Test a child emitting more than a tiny diagnostic.

References

  1. The Open Group, POSIX Shell Command Language ↩