|
JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
|
Cross-platform process launcher aligned with std::thread semantics. More...
#include "jh/macros/platform.h"#include "jh/metax/t_str.h"#include "jh/synchronous/ipc/ipc_limits.h"#include <string>#include <stdexcept>#include <filesystem>#include <iostream>Go to the source code of this file.
Classes | |
| class | jh::sync::ipc::process_launcher< Path, IsBinary > |
| Cross-platform process launcher. More... | |
| struct | jh::sync::ipc::process_launcher< Path, IsBinary >::handle |
| Process handle representing a single launched instance. More... | |
Namespaces | |
| namespace | jh::sync |
| Aggregated entry point for synchronization and coordination facilities. | |
| namespace | jh::sync::ipc |
| Synchronous inter-process coordination primitives. | |
Macros | |
| #define | JH_INTERPROCESS_ALLOW_PARENT_PATH 0 |
Cross-platform process launcher aligned with std::thread semantics.
This class encapsulates the platform-specific differences between POSIX fork() + execl() and Windows CreateProcess(), exposing a unified std::thread-like API.
fork() creates the child, execl() replaces its image. wait() maps to waitpid(). .exe, .bat, .ps1). CreateProcess() is used for launching. wait() maps to WaitForSingleObject(). The template parameter IsBinary exists to simplify build workflows (especially for CMake-generated executables):
".exe" is appended automatically (so "writer" → "writer.exe"). .bat, .ps1; POSIX: may be script with shebang + execute permission). '/' (absolute paths forbidden). "./" segments are meaningless and rejected. ".." handling: JH_INTERPROCESS_ALLOW_PARENT_PATH == 0): any ".." is forbidden. JH_INTERPROCESS_ALLOW_PARENT_PATH == 1: leading "../" prefixes are permitted (one or more), but: "../" segments. ".." segments are allowed. [A-Za-z0-9_.-/]. "./" or use '\': paths are interpreted directly by the filesystem and resolved relative to the current working directory. "./" or mid-path ".." segments are forbidden. "/foo/bar") are forbidden by design. JH_INTERPROCESS_ALLOW_PARENT_PATH): ".." usage is an error. "../" prefixes are permitted; they must be followed by a valid non-empty subpath. cwd. '/') are translated automatically; backslashes are not required. .. in the middle of paths prevents directory traversal vulnerabilities. std::thread: wait()-ed. std::terminate() is invoked. start() for launching. start() returns a unique, move-only handle representing one running process. wait()-ed before destruction. std::terminate(). process_launcher<Path, IsBinary> has its own nested handle type, bound to its executable at compile time.