From 6de90b3c935db0e3ec95a3ac4b390a1e98c4e10a Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 20 May 2023 12:48:17 +0200 Subject: [PATCH] libc: Add getrusage() --- libc/CMakeLists.txt | 1 + libc/include/sys/resource.h | 20 ++++++++++++++++++++ libc/src/sys/resource.cpp | 13 +++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 libc/include/sys/resource.h create mode 100644 libc/src/sys/resource.cpp diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 1123601d..75033f6a 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -26,6 +26,7 @@ set(SOURCES src/sys/utsname.cpp src/sys/mount.cpp src/sys/pstat.cpp + src/sys/resource.cpp ) if(${LUNA_ARCH} STREQUAL "x86_64") diff --git a/libc/include/sys/resource.h b/libc/include/sys/resource.h new file mode 100644 index 00000000..1f6a8d84 --- /dev/null +++ b/libc/include/sys/resource.h @@ -0,0 +1,20 @@ +/* sys/resource.h: System resource management. */ + +#ifndef _SYS_RESOURCE_H +#define _SYS_RESOURCE_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* Get this process or its children's resource usage. */ + int getrusage(int who, struct rusage* ru); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libc/src/sys/resource.cpp b/libc/src/sys/resource.cpp new file mode 100644 index 00000000..f408906d --- /dev/null +++ b/libc/src/sys/resource.cpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +extern "C" +{ + int getrusage(int who, struct rusage* ru) + { + long rc = syscall(SYS_getrusage, who, ru); + __errno_return(rc, int); + } +}