| 1 | #ifndef BASE_PROCESS_H |
| 2 | #define BASE_PROCESS_H |
| 3 | |
| 4 | #include "detect.h" |
| 5 | #include "types.h" |
| 6 | |
| 7 | /** |
| 8 | * Process management. |
| 9 | * |
| 10 | * @defgroup Process Process |
| 11 | */ |
| 12 | |
| 13 | /** |
| 14 | * Returns the ID of the current process. |
| 15 | * |
| 16 | * @ingroup Process |
| 17 | * |
| 18 | * @return PID of the current process. |
| 19 | */ |
| 20 | int process_id(); |
| 21 | |
| 22 | #if !defined(CONF_PLATFORM_ANDROID) |
| 23 | /** |
| 24 | * Determines the initial window state when using @link process_execute @endlink |
| 25 | * to execute a process. |
| 26 | * |
| 27 | * @ingroup Process |
| 28 | * |
| 29 | * @remark Currently only supported on Windows. |
| 30 | */ |
| 31 | enum class EShellExecuteWindowState |
| 32 | { |
| 33 | /** |
| 34 | * The process window is opened in the foreground and activated. |
| 35 | */ |
| 36 | FOREGROUND, |
| 37 | |
| 38 | /** |
| 39 | * The process window is opened in the background without focus. |
| 40 | */ |
| 41 | BACKGROUND, |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * Executes a given file. |
| 46 | * |
| 47 | * @ingroup Process |
| 48 | * |
| 49 | * @param file The file to execute. |
| 50 | * @param window_state The window state how the process window should be shown. |
| 51 | * @param arguments Optional array of arguments to pass to the process. |
| 52 | * @param num_arguments The number of arguments. |
| 53 | * |
| 54 | * @return Handle of the new process, or @link INVALID_PROCESS @endlink on error. |
| 55 | */ |
| 56 | PROCESS process_execute(const char *file, EShellExecuteWindowState window_state, const char **arguments = nullptr, size_t num_arguments = 0); |
| 57 | |
| 58 | /** |
| 59 | * Sends kill signal to a process. |
| 60 | * |
| 61 | * @ingroup Process |
| 62 | * |
| 63 | * @param process Handle of the process to kill. |
| 64 | * |
| 65 | * @return `1` on success, `0` on error. |
| 66 | */ |
| 67 | int process_kill(PROCESS process); |
| 68 | |
| 69 | /** |
| 70 | * Checks if a process is alive. |
| 71 | * |
| 72 | * @ingroup Process |
| 73 | * |
| 74 | * @param process Handle/PID of the process. |
| 75 | * |
| 76 | * @return `true` if the process is currently running, |
| 77 | * @return `false` if the process is not running (dead). |
| 78 | */ |
| 79 | bool process_is_alive(PROCESS process); |
| 80 | #endif // !defined(CONF_PLATFORM_ANDROID) |
| 81 | |
| 82 | #endif |
| 83 | |