forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only the two timeval fields are maintained, as required by the POSIX standard.
- Loading branch information
1 parent
39bfc48
commit 839d3d9
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2022, Lucas Chollet <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <Kernel/API/POSIX/sys/time.h> | ||
#include <Kernel/API/POSIX/sys/types.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct rusage { | ||
struct timeval ru_utime; | ||
struct timeval ru_stime; | ||
long ru_maxrss; | ||
long ru_ixrss; | ||
long ru_idrss; | ||
long ru_isrss; | ||
long ru_minflt; | ||
long ru_majflt; | ||
long ru_nswap; | ||
long ru_inblock; | ||
long ru_oublock; | ||
long ru_msgsnd; | ||
long ru_msgrcv; | ||
long ru_nsignals; | ||
long ru_nvcsw; | ||
long ru_nivcsw; | ||
}; | ||
|
||
#define RUSAGE_SELF 1 | ||
#define RUSAGE_CHILDREN 2 | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2022, Lucas Chollet <[email protected]> | ||
* | ||
* 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; | ||
} | ||
|
||
} |