Motion Master 6.0.0-alpha.86
Next-generation motion control software
Loading...
Searching...
No Matches
process_platform.h File Reference

The three platform-specific steps of running a child process. More...

#include <chrono>
#include <cstdint>
#include <expected>
#include <filesystem>
#include <string>
#include <vector>
Include dependency graph for process_platform.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mm::auto_tuning::detail::Child
 A started child, as the platform identifies it. More...
 

Namespaces

namespace  mm
 
namespace  mm::auto_tuning
 
namespace  mm::auto_tuning::detail
 

Functions

std::expected< Child, std::string > mm::auto_tuning::detail::spawnChild (const std::filesystem::path &binary, const std::vector< std::string > &args, const std::filesystem::path &logFile)
 Runs binary with args, with its output appended to logFile.
 
bool mm::auto_tuning::detail::childAlive (const Child &child)
 Whether child is still running.
 
bool mm::auto_tuning::detail::terminateChild (const Child &child, std::chrono::milliseconds grace)
 Asks child to exit, waits up to grace, then kills it and everything it started.
 

Detailed Description

The three platform-specific steps of running a child process.

Internal to mm::auto_tuning. Implemented once per platform (process_posix.cc, process_windows.cc) so process.cc holds the part that is the same everywhere: the health wait, the version, and the error messages.

A started child is identified by integers, which is what lets process.h name no platform type. On POSIX only the process id is used, and it doubles as the process group id. On Windows the id is for the log line, handle is the process, and group is a job object.

The child is a launcher that runs a second process. The auto-tuning executable unpacks itself on every start and runs the unpacked program as its own child, and that grandchild is the one that holds the port. Measured: a termination signal to the launcher does reach it, because the launcher forwards the signal — but a kill cannot be forwarded, and a kill is exactly what the wedged case needs. So the child is started in its own process group (POSIX) or job object (Windows), and both signals go to that rather than to the one process.