🟩 Create child processes and chain them (also usable with Async library)
Process allows launching, chaining input and output, setting working directory and environment variables of child processes.
Class | Description |
---|---|
SC::Process | Execute a child process with standard file descriptors redirection. |
SC::ProcessChain | Execute multiple child processes chaining input / output between them. |
SC::ProcessEnvironment | Reads current process environment variables. |
SC::ProcessFork | Forks current process exiting child at end of process A fork duplicates a parent process execution state, os handles and private memory. |
🟩 Usable
Library is being used in SC::Plugin and in SC::Tools.
The SC::Process class is used when handling a process in isolation, while the SC::ProcessChain is used when there is need to chain inputs and outputs of multiple processes together.
This is the list of videos that have been recorded showing some of the internal thoughts that have been going into this library:
Some relevant blog posts are:
Execute a child process with standard file descriptors redirection.
Features:
Example: execute child process (launch and wait for it to fully execute)
Example: execute child process, redirecting stdout to a string
Example: launch a child process and wait for it to finish execution
Example: execute child process, filling its stdin with a StringView
Example: read process output using a pipe, using launch + waitForExitSync
Example: Add an environment variable
Example: Redefine an environment variable
Example: Disable environment variable inheritance
Execute multiple child processes chaining input / output between them.
Chains multiple child processes together, so that the output of a process becomes input of another (similar to what happens wit the pipe (|
) operator on Posix shells).
SC::PipeDescriptor from File library is used to chain read / write endpoints of different processes together.
Example: Inherit stdout file descriptor
Example: Read stderr and stdout into a string
Example: Read standard output into a string using a Pipe
Reads current process environment variables.
Example: Print all environment variables to stdout
Forks current process exiting child at end of process A fork duplicates a parent process execution state, os handles and private memory.
Its semantics are quite different from platform to platform but on its most common denominator it can be used to carry on "background" operations on snapshots of current program memory. One relevant use case is serializing to disk or network a live, complex and large data structure. Without the fork the program should either:
Fork avoids memory duplication because it will be shared through Copy On Write (COW) mechanisms. COW ensures that un-modified duplicated memory pages will not occupy additional Physical RAM.
A pair of pipes makes it easy to do some coordination between parent and forked process.
Example: Fork current process modifying memory in forked process leaving parent's one unmodified.
🟦 Complete Features:
💡 Unplanned Features: