mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 08:57:35 +00:00
Kernel: Add getrusage() syscall
Only the two timeval fields are maintained, as required by the POSIX standard.
This commit is contained in:
parent
39bfc48ea7
commit
839d3d9f74
5 changed files with 83 additions and 2 deletions
37
Kernel/Syscalls/resource.cpp
Normal file
37
Kernel/Syscalls/resource.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Lucas Chollet <lucas.chollet@free.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/Process.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$getrusage(int who, Userspace<rusage*> user_usage)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
|
||||
rusage usage {};
|
||||
|
||||
auto const ticks_per_second = TimeManagement::the().ticks_per_second();
|
||||
|
||||
switch (who) {
|
||||
case RUSAGE_SELF:
|
||||
usage.ru_utime = Time::from_ticks(m_ticks_in_user, ticks_per_second).to_timeval();
|
||||
usage.ru_stime = Time::from_ticks(m_ticks_in_kernel, ticks_per_second).to_timeval();
|
||||
break;
|
||||
case RUSAGE_CHILDREN:
|
||||
usage.ru_utime = Time::from_ticks(m_ticks_in_user_for_dead_children, ticks_per_second).to_timeval();
|
||||
usage.ru_stime = Time::from_ticks(m_ticks_in_kernel_for_dead_children, ticks_per_second).to_timeval();
|
||||
break;
|
||||
default:
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
TRY(copy_to_user(user_usage, &usage));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue