Kernel: Add function to enumerate processes in session

This commit is contained in:
Bananymous 2023-08-22 14:52:28 +03:00
parent e33bf62bba
commit d634fec8dc
2 changed files with 16 additions and 0 deletions

View File

@ -47,6 +47,7 @@ namespace Kernel
void exit(int status, int signal); void exit(int status, int signal);
static void for_each_process(const BAN::Function<BAN::Iteration(Process&)>& callback); static void for_each_process(const BAN::Function<BAN::Iteration(Process&)>& callback);
static void for_each_process_in_session(pid_t sid, const BAN::Function<BAN::Iteration(Process&)>& callback);
void add_thread(Thread*); void add_thread(Thread*);
void on_thread_exit(Thread&); void on_thread_exit(Thread&);

View File

@ -36,6 +36,21 @@ namespace Kernel
} }
} }
void Process::for_each_process_in_session(pid_t sid, const BAN::Function<BAN::Iteration(Process&)>& 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) Process* Process::create_process(const Credentials& credentials, pid_t parent, pid_t sid, pid_t pgrp)
{ {
static pid_t s_next_id = 1; static pid_t s_next_id = 1;