CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
processobj.cxh
1#include <cx/closure/closure.h>
2#include <cx/container/sarray.h>
3#include <cx/thread/atomic.h>
4#include <cx/thread/mutex.h>
5
6/// @addtogroup sys_process
7/// @{
8
9/// A process cx launched or attached to
10///
11/// This is a base class; the platform layer provides the derived class holding the native
12/// handle. Release it with procRelease() when finished.
13[methodprefix _procobj] abstract class Process {
14 int64 pid; ///< OS process id
15 int64 starttime; ///< When the process started, used to detect a reused pid
16
17 /// @brief cx forked this process, so cx is responsible for reaping it
18 ///
19 /// Only a child can be waited on, which is also why a process cx did not fork cannot
20 /// report an exit code.
21 bool ischild;
22
23 /// @brief Set once the outcome is known and cached in the two fields below
24 ///
25 /// Read with acquire ordering; everything published before it is then safe to read without
26 /// the lock, which is how the exit status outlives the reap.
27 atomic[bool] exited;
28 int32 exitcode; ///< Valid once `exited` is set; PROC_ExitCodeUnknown if `statusknown` is false
29 int32 termsignal; ///< Unix: signal that killed it, 0 if it exited normally
30 bool statusknown; ///< Set with `exited` when a real exit status was collected
31
32 /// @brief Exit watcher registration id, 0 if never registered
33 ///
34 /// Ids are never reused, so a stale notification for a registration that was since
35 /// cancelled cannot be mistaken for a new one at the same address.
36 int64 watchid;
37
38 string name; ///< Cached, best-effort
39 string exepath; ///< Cached, best-effort
40
41 [noinit] Mutex lock; ///< Guards publication of the exit state
42 [noinit] sarray[closure] onexit; ///< Exit subscribers, fired once outside the lock
43
44 init();
45 destroy();
46}
47
48/// @}