diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-03-30 02:42:51 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-31 23:49:26 +0200 |
commit | e3fd914187b318ed1fda9f806c5edda58622d578 (patch) | |
tree | ac1f9162da08230417cc1f687262b9db18d8c264 /Kernel | |
parent | 47080941cc9641376c17966b5298aaab466fd0d9 (diff) | |
download | serenity-e3fd914187b318ed1fda9f806c5edda58622d578.zip |
Kernel: Send SIGCHLD to the parent process when changing stopped state
This is done also by linux (signal.c:936 in v5.11) at least.
It's a pretty handy notification that allows the parent process to skip
going through a `waitpid` and guesswork to figure out the current state
of a child process.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Thread.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 414f4d8d2f..e835f2ad48 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -911,6 +911,10 @@ void Thread::set_state(State new_state, u8 stop_signal) return IterationDecision::Continue; }); process.unblock_waiters(Thread::WaitBlocker::UnblockFlags::Continued); + // Tell the parent process (if any) about this change. + if (auto parent = Process::from_pid(process.ppid())) { + [[maybe_unused]] auto result = parent->send_signal(SIGCHLD, &process); + } } } @@ -930,6 +934,10 @@ void Thread::set_state(State new_state, u8 stop_signal) return IterationDecision::Continue; }); process.unblock_waiters(Thread::WaitBlocker::UnblockFlags::Stopped, stop_signal); + // Tell the parent process (if any) about this change. + if (auto parent = Process::from_pid(process.ppid())) { + [[maybe_unused]] auto result = parent->send_signal(SIGCHLD, &process); + } } } else if (m_state == Dying) { VERIFY(previous_state != Blocked); |