diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-11-12 15:36:49 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-11-12 15:36:49 +0000 |
commit | f06e5a86b194219cf631cb10a09ba5046362bf7d (patch) | |
tree | bcdaf05e5094844ec8f4c4aa0ab96cc212bd9bc7 /cpukit/libcsupport/src/getrusage.c | |
parent | 2008-11-12 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-f06e5a86b194219cf631cb10a09ba5046362bf7d.tar.bz2 |
2008-11-12 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/Makefile.am: Add getrusage().
* libcsupport/src/getrusage.c: New file.
Diffstat (limited to 'cpukit/libcsupport/src/getrusage.c')
-rw-r--r-- | cpukit/libcsupport/src/getrusage.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cpukit/libcsupport/src/getrusage.c b/cpukit/libcsupport/src/getrusage.c new file mode 100644 index 0000000000..3e57139e99 --- /dev/null +++ b/cpukit/libcsupport/src/getrusage.c @@ -0,0 +1,51 @@ +/* + * COPYRIGHT (c) 1989-2008. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/resource.h> +#include <errno.h> + +#include <rtems.h> +#include <rtems/seterr.h> + +int getrusage(int who, struct rusage *usage) +{ + struct timespec uptime; + struct timeval rtime; + + if ( !usage ) + rtems_set_errno_and_return_minus_one( EFAULT ); + + /* + * RTEMS only has a single process so there are no children. + * The single process has been running since the system + * was booted and since there is no distinction between system + * and user time, we will just report the uptime. + */ + if (who == RUSAGE_SELF) { + rtems_clock_get_uptime( &uptime ); + + rtime.tv_sec = uptime.tv_sec; + rtime.tv_usec = uptime.tv_nsec / 1000; + + usage->ru_utime = rtime; + usage->ru_stime = rtime; + + return 0; + } else if (who == RUSAGE_CHILDREN) { + rtems_set_errno_and_return_minus_one( ENOSYS ); + } + rtems_set_errno_and_return_minus_one( EINVAL ); +} + |