VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
process.h File Reference

Cross-platform child process management with I/O piping and async callbacks. More...

#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "./macros.h"
Include dependency graph for process.h:

Go to the source code of this file.

Classes

 Cross-platform child process with async I/O and state notification. More...

Namespaces

Detailed Description

Cross-platform child process management with I/O piping and async callbacks.

Process provides a Qt-QProcess-inspired API for launching, monitoring and communicating with child processes. It supports:

  • Asynchronous state change, I/O ready-read and exit callbacks.
  • Multiple channel modes (separate stdout/stderr, merged, or forwarded to parent).
  • Line-by-line and bulk I/O reading from stdout and stderr.
  • Writing to stdin with a configurable timeout.
  • Synchronous helpers (execute, start_detached) for fire-and-forget use cases.

Channel modes:

Mode stdout stderr
kSeparateMode Buffered pipe Buffered pipe
kMergedMode Buffered pipe Merged into stdout
kForwardedMode Forwarded to parent Forwarded to parent
kForwardedOutputMode Forwarded to parent Buffered pipe
kForwardedErrorMode Buffered pipe Forwarded to parent
Note
  • All callbacks are invoked from an internal monitor thread; access shared state with care.
  • close() requests termination and optionally force-kills after a timeout.
  • Process objects are non-moveable and non-copyable.
  • The destructor waits kDestructorWaitTimeoutMs (5 s) for the process to exit.
Example
std::string line;
while (proc.can_read_line_stdout()) {
proc.read_line_stdout(line);
// handle line
}
});
// handle exit
});
proc.start("/usr/bin/ls", {"-la"});