VLink  2.0.0
A high-performance communication middleware
process.h File Reference

Portable child-process driver with asynchronous I/O notifications. More...

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

Go to the source code of this file.

Classes

class  vlink::Process
 Owns and drives a single child process with asynchronous I/O reporting. More...
 

Namespaces

 

Detailed Description

Portable child-process driver with asynchronous I/O notifications.

vlink::Process spawns a single child program at a time and exposes a QProcess-style surface for inspecting its lifecycle, reading captured output, writing to its standard input, and triggering termination. Output capture, exit notification, and timer-driven polling all run on an internal monitor thread.

Capability groups exposed by the class:

Group Representative members
Lifecycle start, start_command, terminate, kill, close
Process metadata get_process_id, get_state, get_error, get_exit_code
Environment & cwd set_environment, set_inherit_environment, set_working_directory
I/O routing set_process_mode, get_process_mode
stdout/stderr capture read_line_stdout, read_all, bytes_available_stdout
stdin writing write, close_write_channel
Async notifications register_finished_callback, register_ready_read_stdout_callback
Synchronous waits wait_for_started, wait_for_finished, wait_for_ready_read
Static helpers execute, start_detached

I/O channel routing modes:

Mode stdout stderr
kSeparateMode Buffered pipe Buffered pipe
kMergedMode Buffered pipe Merged into stdout
kForwardedMode Inherits parent Inherits parent
kForwardedOutputMode Inherits parent Buffered pipe
kForwardedErrorMode Buffered pipe Inherits parent
Note
  • Every callback fires from the monitor thread; protect shared caller state accordingly.
  • The destructor first sends SIGTERM, drains pending I/O, then optionally escalates to SIGKILL after kDestructorWaitTimeoutMs (5000 ms) before joining.
  • The class is non-copyable and non-movable.
Example
std::string line;
while (proc.can_read_line_stdout()) {
proc.read_line_stdout(line);
}
});
(void)code;
(void)status;
});
proc.start("/usr/bin/ls", {"-la"});