Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
Process.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
20
21#pragma once
22
23#include "sese/Util.h"
24#include "sese/util/Result.h"
25
26namespace sese::system {
27
29class Process {
30public:
31 using Ptr = std::unique_ptr<Process>;
32
36 static Process::Ptr create(const char *command) noexcept;
37
38
39 static Result<Process::Ptr> createEx(const char *command) noexcept;
40
43 [[nodiscard]] static pid_t getCurrentProcessId() noexcept;
44
47 [[nodiscard]] int wait() const noexcept;
48
51 [[nodiscard]] bool kill() const noexcept;
52
55 [[nodiscard]] pid_t getProcessId() const noexcept;
56
57private:
58 Process() = default;
59
60#ifdef _WIN32
61public:
62 virtual ~Process() noexcept;
63
64private:
65 void *startup_info = nullptr;
66 void *process_info = nullptr;
67#else
68public:
69 virtual ~Process() noexcept = default;
70
71private:
72 // Unix-like 执行新进程实现
73 static void exec(char *p_command) noexcept;
74 // 计算字符串中参数的个数
75 static size_t count(const char *p_command) noexcept;
76 // 将下一个空格设置为 '\0',并返回空格下一个字符的指针
77 static char *spilt(char *p_command) noexcept;
78
79 pid_t id = -1;
80#endif
81};
82} // namespace sese::system