diff --git a/kernel/include/kernel/Process.h b/kernel/include/kernel/Process.h index 8bacfd654d..f1fb007afe 100644 --- a/kernel/include/kernel/Process.h +++ b/kernel/include/kernel/Process.h @@ -47,6 +47,7 @@ namespace Kernel void exit(int status, int signal); static void for_each_process(const BAN::Function& callback); + static void for_each_process_in_session(pid_t sid, const BAN::Function& callback); void add_thread(Thread*); void on_thread_exit(Thread&); diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 43f73e358f..c0ab10e8c9 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -36,6 +36,21 @@ namespace Kernel } } + void Process::for_each_process_in_session(pid_t sid, const BAN::Function& callback) + { + LockGuard _(s_process_lock); + + for (auto* process : s_processes) + { + if (process->sid() != sid) + continue; + auto ret = callback(*process); + if (ret == BAN::Iteration::Break) + return; + ASSERT(ret == BAN::Iteration::Continue); + } + } + Process* Process::create_process(const Credentials& credentials, pid_t parent, pid_t sid, pid_t pgrp) { static pid_t s_next_id = 1;