This repository was archived by the owner on May 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkill.hpp
More file actions
43 lines (37 loc) · 1.2 KB
/
kill.hpp
File metadata and controls
43 lines (37 loc) · 1.2 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
#pragma once
#include <all.hpp>
class KillCommand : public liteshell::BaseCommand
{
public:
KillCommand()
: liteshell::BaseCommand(
"kill",
"Kill a subprocess with the given PID and exit code ",
"",
liteshell::CommandConstraint(
"pid", "The PID of the subprocess to kill", true,
"exit_code", "The exit code to use when killing the subprocess (default: 1)", false)) {}
DWORD run(const liteshell::Context &context)
{
DWORD pid = std::stoul(context.get("pid"));
UINT exit_code = 1;
try
{
exit_code = std::stoul(context.get("exit_code"));
}
catch (liteshell::ArgumentMissingError &)
{
// pass
}
for (auto wrapper_ptr : context.client->get_subprocesses())
{
if (wrapper_ptr->pid() == pid)
{
wrapper_ptr->kill(exit_code);
std::cout << "Terminated process " << pid << " with exit code " << exit_code << std::endl;
return 0;
}
}
throw std::invalid_argument("Cannot find a subprocess with the given PID");
}
};