forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
patch-2
/
utils.h
44 lines (35 loc) · 1.14 KB
patch-2
/
utils.h
File metadata and controls
- Code
- Blame
44 lines (35 loc) · 1.14 KB
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
#pragma once
#if defined(_WIN32)
#include <process.h>
#include <windows.h>
using pid_t = DWORD;
#elif defined(__APPLE__) || defined(__linux__)
#include <signal.h>
#include <spawn.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#endif
#include <string>
#include <vector>
#include "utils/result.hpp"
namespace cortex::process {
// set pid to this value to signal that this pid should not be used.
constexpr pid_t PID_TERMINATED = 0;
struct ProcessInfo {
pid_t pid;
#ifdef _WIN32
// hJob is used to terminate process and its children.
// hStdOut and hStdErr must be manually closed upon process termination.
HANDLE hJob, hStdOut, hStdErr;
#endif
};
std::string ConstructWindowsCommandLine(const std::vector<std::string>& args);
std::vector<char*> ConvertToArgv(const std::vector<std::string>& args);
cpp::result<ProcessInfo, std::string> SpawnProcess(
const std::vector<std::string>& command,
const std::string& stdout_file = "", const std::string& stderr_file = "");
bool IsProcessAlive(ProcessInfo& proc_info);
bool WaitProcess(ProcessInfo& proc_info);
bool KillProcess(ProcessInfo& proc_info);
} // namespace cortex::process