summaryrefslogtreecommitdiff
path: root/Kernel/Process.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-12-03 01:12:26 +0100
committerAndreas Kling <awesomekling@gmail.com>2018-12-03 01:14:19 +0100
commite7cc08226f5af4711f8e8438d7132c35b10666ed (patch)
treedef609f70bb376b9ab989c3b60792abbf2989147 /Kernel/Process.cpp
parent4bc87dc7b99c4f7a9270e23e5958b4c93fe76033 (diff)
downloadserenity-e7cc08226f5af4711f8e8438d7132c35b10666ed.zip
Implement basic support for times().
The kernel now bills processes for time spent in kernelspace and userspace separately. The accounting is forwarded to the parent process in reap(). This makes the "time" builtin in bash work.
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r--Kernel/Process.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index c47aaf5def..3a1db69a26 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -1415,6 +1415,14 @@ int Process::reap(Process& process)
{
InterruptDisabler disabler;
int exit_status = (process.m_termination_status << 8) | process.m_termination_signal;
+
+ if (process.ppid()) {
+ auto* parent = Process::from_pid(process.ppid());
+ ASSERT(parent);
+ parent->m_ticks_in_user_for_dead_children += process.m_ticks_in_user + process.m_ticks_in_user_for_dead_children;
+ parent->m_ticks_in_kernel_for_dead_children += process.m_ticks_in_kernel + process.m_ticks_in_kernel_for_dead_children;
+ }
+
dbgprintf("reap: %s(%u) {%s}\n", process.name().characters(), process.pid(), toString(process.state()));
ASSERT(process.state() == Dead);
g_processes->remove(&process);
@@ -1763,3 +1771,14 @@ int Process::sys$mkdir(const char* pathname, mode_t mode)
return error;
return 0;
}
+
+Unix::clock_t Process::sys$times(Unix::tms* times)
+{
+ if (!validate_write_typed(times))
+ return -EFAULT;
+ times->tms_utime = m_ticks_in_user;
+ times->tms_stime = m_ticks_in_kernel;
+ times->tms_cutime = m_ticks_in_user_for_dead_children;
+ times->tms_cstime = m_ticks_in_kernel_for_dead_children;
+ return 0;
+}