13 #ifndef __STOUT_OS_POSIX_KILLTREE_HPP__ 14 #define __STOUT_OS_POSIX_KILLTREE_HPP__ 32 inline std::set<pid_t>
children(
pid_t,
const std::list<Process>&,
bool);
37 const std::set<pid_t>&,
38 const std::list<Process>&);
62 bool sessions =
false)
72 std::queue<pid_t> queue;
77 if (process.isNone()) {
78 foreach (
const Process& _process, processes.
get()) {
79 if (groups && _process.
group == pid) {
80 queue.push(_process.
pid);
81 }
else if (sessions &&
84 queue.push(_process.
pid);
91 return std::list<ProcessTree>();
100 std::set<pid_t> groups;
101 std::set<pid_t> sessions;
109 if (process.isSome() && (groups || sessions)) {
114 visited.groups.insert(parent->
group);
117 visited.sessions.insert(parent->
session.
get());
122 while (!queue.empty()) {
123 pid_t pid = queue.front();
126 if (visited.pids.count(pid) != 0) {
133 if (process.isError()) {
134 return Error(process.error());
135 }
else if (process.isNone()) {
144 visited.pids.insert(pid);
145 visited.processes.push_back(process.get());
163 if (visited.groups.count(group) == 0) {
164 foreach (
const Process& process, processes.
get()) {
165 if (process.
group == group) {
166 queue.push(process.
pid);
169 visited.groups.insert(group);
178 if (sessions && process->session.isSome()) {
179 pid_t session = process->session.get();
180 if (visited.sessions.count(session) == 0) {
181 foreach (
const Process& process, processes.
get()) {
183 queue.push(process.
pid);
186 visited.sessions.insert(session);
192 foreach (
pid_t pid, visited.pids) {
215 foreach (
pid_t pid, visited.pids) {
220 return pstrees(visited.pids, visited.processes);
225 #endif // __STOUT_OS_POSIX_KILLTREE_HPP__ Definition: errorbase.hpp:36
Definition: option.hpp:29
T & get()&
Definition: try.hpp:80
const pid_t group
Definition: process.hpp:55
Try< std::list< ProcessTree > > pstrees(const std::set< pid_t > &, const std::list< Process > &)
Definition: pstree.hpp:84
Try< std::list< Process > > processes()
Definition: os.hpp:184
Definition: posix_signalhandler.hpp:23
const Option< pid_t > session
Definition: process.hpp:56
bool isSome() const
Definition: option.hpp:116
DWORD pid_t
Definition: windows.hpp:181
Definition: process.hpp:32
const pid_t pid
Definition: process.hpp:53
Try< std::list< ProcessTree > > killtree(pid_t pid, int signal, bool groups=false, bool sessions=false)
Definition: killtree.hpp:58
const T & get() const &
Definition: option.hpp:119
static Try error(const E &e)
Definition: try.hpp:43
int kill(pid_t pid, int sig)
Definition: kill.hpp:21
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
bool isError() const
Definition: try.hpp:78
std::set< pid_t > children(pid_t, const std::list< Process > &, bool)
Definition: os.hpp:217
Definition: executor.hpp:48
Try< std::set< pid_t > > pids()
Definition: freebsd.hpp:62