subprocess::posix_process class

Abstraction of a POSIX process with stdin, stdout, and stderr.

This class encapsulates a POSIX process. It is the actual interface for running subprocesses. The descriptors in this class can be pointed to each other, and to other opened descriptors.

posix::spawnp is used to spawn child processes. The following actions are performed on descriptors on execution:

  • All descriptors are opened with a call to descriptor::open().
  • descriptor::fd() is used to get descriptors for the child process and dup them to stdin, stdout, and stderr
  • In the child process, the descriptors returned by descriptor::fd() would be closed.
  • After the process is spawned, the parent process closes each descriptor with a call to descriptor::close.

Therefore, while providing your own descriptors, it is important to correctly implement open(), fd(), and close() calls to the class that derives from subprocess::descriptor.

Constructors, destructors, conversion operators

posix_process(std::string cmd) explicit

Public functions

void execute()
Spawns the child process.
auto wait() -> int
Reaps the child process from the process table.
auto in() -> const descriptor&
auto out() -> const descriptor&
auto err() -> const descriptor&
void in(descriptor_ptr&& fd)
void out(descriptor_ptr&& fd)
void err(descriptor_ptr&& fd)
void out(err_t)
void err(out_t)

Function documentation

void subprocess::posix_process::execute()

Spawns the child process.

This method performs shell expansion, manages the file descriptors, and ensures that the child process is spawned with the correct descriptors.

It does NOT reap the child process from the process table.

int subprocess::posix_process::wait()

Reaps the child process from the process table.

Returns int exit status of the process