STTNet
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Static Public Member Functions | List of all members
stt::system::Process Class Reference

Static utility class for process management. More...

#include <sttnet_English.h>

Static Public Member Functions

template<class... Args>
static bool startProcess (const std::string &name, const int &sec=-1, Args...args)
 Start a new process (with the option to restart periodically) More...
 
template<class Fn , class... Args>
static std::enable_if
<!std::is_convertible< Fn,
std::string >::value, bool >
::type 
startProcess (Fn &&fn, const int &sec=-1, Args &&...args)
 Create a child process through a function (with the option to restart periodically) More...
 

Detailed Description

Static utility class for process management.

Member Function Documentation

template<class... Args>
static bool stt::system::Process::startProcess ( const std::string &  name,
const int &  sec = -1,
Args...  args 
)
inlinestatic

Start a new process (with the option to restart periodically)

When sec == -1, the child process is started only once; otherwise, an auxiliary child process is created to restart the target process periodically.

  • When starting periodically, the auxiliary process blocks all signals.
  • The started target process blocks all signals except SIGCHLD and SIGTERM.
Parameters
ArgsVariable parameter types (used to pass to the target program's argv)
namePath of the program to execute (e.g., /usr/bin/myapp)
secTime interval (in seconds). If -1, start only once without periodicity.
argsStartup parameters (the first parameter must be the program name, i.e., argv[0], no need to add nullptr at the end)
Returns
true The parent process returns true indicating successful startup (or scheduling)
false Returns false when fork or execv fails
Note
  • No need to manually add nullptr to the parameters; it is added internally.
  • No exception is thrown on execution failure; returns false.
  • execv replaces the current process image in the child process and does not return.
template<class Fn , class... Args>
static std::enable_if<!std::is_convertible<Fn, std::string>::value, bool>::type stt::system::Process::startProcess ( Fn &&  fn,
const int &  sec = -1,
Args &&...  args 
)
inlinestatic

Create a child process through a function (with the option to restart periodically)

Use a callable object (such as Lambda, function pointer, std::function) as the main logic of the new child process.

  • When sec == -1, the function is executed only once;
  • Otherwise, an auxiliary process is created to periodically fork and execute the function.
Parameters
FnCallable object type (such as function, Lambda)
ArgsParameter types for the callable object
fnFunction or callable object to execute
secTime interval (in seconds). If -1, execute only once without periodicity.
argsParameters to pass to the function
Returns
true The parent process returns true indicating successful startup; the child process also returns true (for chaining, etc.)
false Failed to create the process
Note
  • The actual execution of the function is in the newly forked child process.
  • The function fn must be callable; parameter types must be perfectly forwarded.
  • The child process exits after execution; the auxiliary process periodically recreates it.

The documentation for this class was generated from the following file: