File: process_handle.adoc

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (109 lines) | stat: -rw-r--r-- 4,416 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
== `process_handle.hpp`
[#process_handle]

A process handle is an unmanaged version of a process.
This means it does not terminate the process on destruction and
will not keep track of the exit-code.

NOTE: that the exit code might be discovered early, during a call to `running`.
Thus it can only be discovered that process has exited already.

[source,cpp]
----

template<typename Executor = net::any_io_executor>
struct basic_process_handle
{
    // The native handle of the process. 
    /* This might be undefined on posix systems that only support signals */
    using native_handle_type = implementation_defined;

    // The executor_type of the process_handle
    using executor_type =  Executor;

    // Getter for the executor
    executor_type get_executor();

    // Rebinds the process_handle to another executor.
    template<typename Executor1>
    struct rebind_executor
    {
        // The socket type when rebound to the specified executor.
        typedef basic_process_handle<Executor1> other;
    };


    // Construct a basic_process_handle from an execution_context.
    /*
    * @tparam ExecutionContext The context must fulfill the asio::execution_context requirements
    */
    template<typename ExecutionContext>
    basic_process_handle(ExecutionContext &context);

    // Construct an empty process_handle from an executor.
    basic_process_handle(executor_type executor);

    // Construct an empty process_handle from an executor and bind it to a pid.
    /* On NON-linux posix systems this call is not able to obtain a file-descriptor and will thus 
     * rely on signals.
     */
    basic_process_handle(executor_type executor, pid_type pid);

    // Construct an empty process_handle from an executor and bind it to a pid and the native-handle
    /* On some non-linux posix systems this overload is not present.
     */
    basic_process_handle(executor_type executor, pid_type pid, native_handle_type process_handle);

    // Move construct and rebind the executor.
    template<typename Executor1>
    basic_process_handle(basic_process_handle<Executor1> &&handle);

    // Get the id of the process
    pid_type id() const
    { return pid_; }

    // Terminate the process if it's still running and ignore the result
    void terminate_if_running(error_code &);

    // Throwing @overload void terminate_if_running(error_code & ec;
    void terminate_if_running();
    // wait for the process to exit and store the exit code in exit_status.
    void wait(native_exit_code_type &exit_status, error_code &ec);
    // Throwing @overload wait(native_exit_code_type &exit_code, error_code & ec)
    void wait(native_exit_code_type &exit_status);

    // Sends the process a signal to ask for an interrupt, which the process may interpret as a shutdown.
    /* Maybe be ignored by the subprocess. */
    void interrupt(error_code &ec);

    // Throwing @overload void interrupt()
    void interrupt();

    // Sends the process a signal to ask for a graceful shutdown. Maybe be ignored by the subprocess.
    void request_exit(error_code &ec);

    // Throwing @overload void request_exit(error_code & ec)
    void request_exit()

    // Unconditionally terminates the process and stores the exit code in exit_status.
    void terminate(native_exit_code_type &exit_status, error_code &ec);\
    // Throwing @overload void terminate(native_exit_code_type &exit_code, error_code & ec)
    void terminate(native_exit_code_type &exit_status);/

    // Checks if the current process is running. 
    /*If it has already completed, it assigns the exit code to `exit_code`.
     */ 
    bool running(native_exit_code_type &exit_code, error_code &ec);
    // Throwing @overload bool running(native_exit_code_type &exit_code, error_code & ec)
    bool running(native_exit_code_type &exit_code);

    // Check if the process handle is referring to an existing process.
    bool is_open() const;

    // Asynchronously wait for the process to exit and assign the native exit-code to the reference.
    // The exit_status can indicate that a process has already be waited for, e.g. when terminate is called.
    template<BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(void(error_code))
             WaitHandler = net::default_completion_token_t<executor_type>>
    auto async_wait(native_exit_code_type &exit_status, WaitHandler &&handler = net::default_completion_token_t<executor_type>());
};
----