mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
2.5-18.1
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
# Copyright (C) 1991, 1992, 1994, 1995, 1997 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1991,1992,1994,1995,1997,2005 Free Software Foundation, Inc.
|
||||
# This file is part of the GNU C Library.
|
||||
|
||||
# The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -24,4 +24,6 @@ headers := sys/resource.h bits/resource.h sys/vlimit.h sys/vtimes.h \
|
||||
routines := getrlimit setrlimit getrlimit64 setrlimit64 getrusage ulimit \
|
||||
vlimit vtimes getpriority setpriority nice
|
||||
|
||||
tests = tst-getrlimit
|
||||
|
||||
include ../Rules
|
||||
|
37
resource/getpriority.c
Normal file
37
resource/getpriority.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* Copyright (C) 1991,95,96,97,2000,02 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
/* Return the highest priority of any process specified by WHICH and WHO
|
||||
(see <sys/resource.h>); if WHO is zero, the current process, process group,
|
||||
or user (as specified by WHO) is used. A lower priority number means higher
|
||||
priority. Priorities range from PRIO_MIN to PRIO_MAX. */
|
||||
int
|
||||
getpriority (which, who)
|
||||
enum __priority_which which;
|
||||
id_t who;
|
||||
{
|
||||
__set_errno (ENOSYS);
|
||||
return -1;
|
||||
}
|
||||
libc_hidden_def (getpriority)
|
||||
|
||||
stub_warning (getpriority)
|
||||
#include <stub-tag.h>
|
34
resource/getrlimit.c
Normal file
34
resource/getrlimit.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Put the soft and hard limits for RESOURCE in *RLIMITS.
|
||||
Returns 0 if successful, -1 if not (and sets errno). */
|
||||
int
|
||||
__getrlimit (enum __rlimit_resource resource, struct rlimit *rlimits)
|
||||
{
|
||||
__set_errno (ENOSYS);
|
||||
return -1;
|
||||
}
|
||||
weak_alias (__getrlimit, getrlimit)
|
||||
|
||||
stub_warning (getrlimit)
|
||||
#include <stub-tag.h>
|
43
resource/getrlimit64.c
Normal file
43
resource/getrlimit64.c
Normal file
@ -0,0 +1,43 @@
|
||||
/* Copyright (C) 1991, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Put the soft and hard limits for RESOURCE in *RLIMITS.
|
||||
Returns 0 if successful, -1 if not (and sets errno). */
|
||||
int
|
||||
getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
|
||||
{
|
||||
struct rlimit rlimits32;
|
||||
|
||||
if (__getrlimit (resource, &rlimits32) < 0)
|
||||
return -1;
|
||||
|
||||
if (rlimits32.rlim_cur == RLIM_INFINITY)
|
||||
rlimits->rlim_cur = RLIM64_INFINITY;
|
||||
else
|
||||
rlimits->rlim_cur = rlimits32.rlim_cur;
|
||||
if (rlimits32.rlim_max == RLIM_INFINITY)
|
||||
rlimits->rlim_max = RLIM64_INFINITY;
|
||||
else
|
||||
rlimits->rlim_max = rlimits32.rlim_max;
|
||||
|
||||
return 0;
|
||||
}
|
35
resource/getrusage.c
Normal file
35
resource/getrusage.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <sys/resource.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Return resource usage information on process indicated by WHO
|
||||
and put it in *USAGE. Returns 0 for success, -1 for failure. */
|
||||
int
|
||||
__getrusage (who, usage)
|
||||
enum __rusage_who who;
|
||||
struct rusage *usage;
|
||||
{
|
||||
__set_errno (ENOSYS);
|
||||
return -1;
|
||||
}
|
||||
stub_warning (getrusage)
|
||||
|
||||
weak_alias (__getrusage, getrusage)
|
||||
#include <stub-tag.h>
|
33
resource/nice.c
Normal file
33
resource/nice.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* Copyright (C) 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Increment the scheduling priority of the calling process by INCR.
|
||||
The superuser may use a negative INCR to decrement the priority. */
|
||||
int
|
||||
nice (incr)
|
||||
int incr;
|
||||
{
|
||||
__set_errno (ENOSYS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
stub_warning (nice)
|
||||
#include <stub-tag.h>
|
36
resource/setpriority.c
Normal file
36
resource/setpriority.c
Normal file
@ -0,0 +1,36 @@
|
||||
/* Copyright (C) 1991,95,96,97,2000,02 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
/* Set the priority of all processes specified by WHICH and WHO
|
||||
to PRIO. Returns 0 on success, -1 on errors. */
|
||||
int
|
||||
setpriority (which, who, prio)
|
||||
enum __priority_which which;
|
||||
id_t who;
|
||||
int prio;
|
||||
{
|
||||
__set_errno (ENOSYS);
|
||||
return -1;
|
||||
}
|
||||
libc_hidden_def (setpriority)
|
||||
|
||||
stub_warning (setpriority)
|
||||
#include <stub-tag.h>
|
37
resource/setrlimit.c
Normal file
37
resource/setrlimit.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* Copyright (C) 1991, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Set the soft and hard limits for RESOURCE to *RLIMITS.
|
||||
Only the super-user can increase hard limits.
|
||||
Return 0 if successful, -1 if not (and sets errno). */
|
||||
int
|
||||
setrlimit (resource, rlimits)
|
||||
enum __rlimit_resource resource;
|
||||
const struct rlimit *rlimits;
|
||||
{
|
||||
__set_errno (ENOSYS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
stub_warning (setrlimit)
|
||||
#include <stub-tag.h>
|
43
resource/setrlimit64.c
Normal file
43
resource/setrlimit64.c
Normal file
@ -0,0 +1,43 @@
|
||||
/* Copyright (C) 1991,1995,1996,1997,1998,2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Set the soft and hard limits for RESOURCE to *RLIMITS.
|
||||
Only the super-user can increase hard limits.
|
||||
Return 0 if successful, -1 if not (and sets errno). */
|
||||
int
|
||||
setrlimit64 (resource, rlimits)
|
||||
enum __rlimit_resource resource;
|
||||
const struct rlimit64 *rlimits;
|
||||
{
|
||||
struct rlimit rlimits32;
|
||||
|
||||
if (rlimits->rlim_cur >= RLIM_INFINITY)
|
||||
rlimits32.rlim_cur = RLIM_INFINITY;
|
||||
else
|
||||
rlimits32.rlim_cur = rlimits->rlim_cur;
|
||||
if (rlimits->rlim_max >= RLIM_INFINITY)
|
||||
rlimits32.rlim_max = RLIM_INFINITY;
|
||||
else
|
||||
rlimits32.rlim_max = rlimits->rlim_max;
|
||||
|
||||
return __setrlimit (resource, &rlimits32);
|
||||
}
|
112
resource/tst-getrlimit.c
Normal file
112
resource/tst-getrlimit.c
Normal file
@ -0,0 +1,112 @@
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
|
||||
static struct
|
||||
{
|
||||
const char *name;
|
||||
int resource;
|
||||
bool required;
|
||||
} tests[] =
|
||||
{
|
||||
/* The following 7 limits are part of POSIX and must exist. */
|
||||
{ "RLIMIT_CORE", RLIMIT_CORE, true },
|
||||
{ "RLIMIT_CPU", RLIMIT_CPU, true },
|
||||
{ "RLIMIT_DATA", RLIMIT_DATA, true },
|
||||
{ "RLIMIT_FSIZE", RLIMIT_FSIZE, true },
|
||||
{ "RLIMIT_NOFILE", RLIMIT_NOFILE, true },
|
||||
{ "RLIMIT_STACK", RLIMIT_STACK, true },
|
||||
{ "RLIMIT_AS", RLIMIT_AS, true },
|
||||
/* The following are traditional Unix limits which are also
|
||||
expected (by us). */
|
||||
{ "RLIMIT_RSS", RLIMIT_RSS, true },
|
||||
{ "RLIMIT_NPROC", RLIMIT_NPROC, true },
|
||||
/* The following are extensions. */
|
||||
#ifdef RLIMIT_MEMLOCK
|
||||
{ "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK, false },
|
||||
#endif
|
||||
#ifdef RLIMIT_LOCKS
|
||||
{ "RLIMIT_LOCKS", RLIMIT_LOCKS, false },
|
||||
#endif
|
||||
#ifdef RLIMIT_SIGPENDING
|
||||
{ "RLIMIT_SIGPENDING", RLIMIT_SIGPENDING, false },
|
||||
#endif
|
||||
#ifdef RLIMIT_MSGQUEUE
|
||||
{ "RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE, false },
|
||||
#endif
|
||||
#ifdef RLIMIT_NICE
|
||||
{ "RLIMIT_NICE", RLIMIT_NICE, false },
|
||||
#endif
|
||||
#ifdef RLIMIT_RTPRIO
|
||||
{ "RLIMIT_RTPRIO", RLIMIT_RTPRIO, false },
|
||||
#endif
|
||||
};
|
||||
#define ntests (sizeof (tests) / sizeof (tests[0]))
|
||||
|
||||
|
||||
static int
|
||||
do_test (void)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
for (int i = 0; i < ntests; ++i)
|
||||
{
|
||||
bool this_ok = true;
|
||||
|
||||
struct rlimit r;
|
||||
int res = getrlimit (tests[i].resource, &r);
|
||||
if (res == -1)
|
||||
{
|
||||
if (errno == EINVAL)
|
||||
{
|
||||
if (tests[i].required)
|
||||
{
|
||||
printf ("limit %s expectedly not available for getrlimit\n",
|
||||
tests[i].name);
|
||||
status = 1;
|
||||
this_ok = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("getrlimit for %s returned unexpected error: %m\n",
|
||||
tests[i].name);
|
||||
status = 1;
|
||||
this_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
struct rlimit64 r64;
|
||||
res = getrlimit64 (tests[i].resource, &r64);
|
||||
if (res == -1)
|
||||
{
|
||||
if (errno == EINVAL)
|
||||
{
|
||||
if (tests[i].required)
|
||||
{
|
||||
printf ("limit %s expectedly not available for getrlimit64"
|
||||
"\n", tests[i].name);
|
||||
status = 1;
|
||||
this_ok = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("getrlimit64 for %s returned unexpected error: %m\n",
|
||||
tests[i].name);
|
||||
status = 1;
|
||||
this_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this_ok)
|
||||
printf ("limit %s OK\n", tests[i].name);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#define TEST_FUNCTION do_test ()
|
||||
#include "../test-skeleton.c"
|
39
resource/ulimit.c
Normal file
39
resource/ulimit.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
/* Function depends on CMD:
|
||||
1 = Return the limit on the size of a file, in units of 512 bytes.
|
||||
2 = Set the limit on the size of a file to NEWLIMIT. Only the
|
||||
super-user can increase the limit.
|
||||
3 = Return the maximum possible address of the data segment.
|
||||
4 = Return the maximum number of files that the calling process
|
||||
can open.
|
||||
Returns -1 on errors. */
|
||||
long int
|
||||
__ulimit (int cmd, ...)
|
||||
{
|
||||
__set_errno (ENOSYS);
|
||||
return -1;
|
||||
}
|
||||
weak_alias (__ulimit, ulimit)
|
||||
|
||||
stub_warning (ulimit)
|
||||
#include <stub-tag.h>
|
51
resource/vlimit.c
Normal file
51
resource/vlimit.c
Normal file
@ -0,0 +1,51 @@
|
||||
/* Copyright (C) 1991, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
/* This is generic in the sense that it will work with the BSD, SYSV,
|
||||
or stub versions of getrlimit. Separate versions could be written
|
||||
for efficiency, but it's probably not worth it. */
|
||||
|
||||
#include <sys/vlimit.h>
|
||||
#include <sys/resource.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Set the soft limit for RESOURCE to be VALUE.
|
||||
Returns 0 for success, -1 for failure. */
|
||||
int
|
||||
vlimit (resource, value)
|
||||
enum __vlimit_resource resource;
|
||||
int value;
|
||||
{
|
||||
if (resource >= LIM_CPU && resource <= LIM_MAXRSS)
|
||||
{
|
||||
/* The rlimit codes happen to each be one less
|
||||
than the corresponding vlimit codes. */
|
||||
enum __rlimit_resource rlimit_res =
|
||||
(enum __rlimit_resource) ((int) resource - 1);
|
||||
struct rlimit lims;
|
||||
|
||||
if (__getrlimit (rlimit_res, &lims) < 0)
|
||||
return -1;
|
||||
|
||||
lims.rlim_cur = value;
|
||||
return __setrlimit (rlimit_res, &lims);
|
||||
}
|
||||
|
||||
__set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
65
resource/vtimes.c
Normal file
65
resource/vtimes.c
Normal file
@ -0,0 +1,65 @@
|
||||
/* Copyright (C) 1991, 1997, 1998 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/vtimes.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
/* Return the number of 1/VTIMES_UNITS_PER_SECOND-second
|
||||
units in the `struct timeval' TV. */
|
||||
#define TIMEVAL_TO_VTIMES(tv) \
|
||||
((tv.tv_sec * VTIMES_UNITS_PER_SECOND) + \
|
||||
(tv.tv_usec * VTIMES_UNITS_PER_SECOND / 1000000))
|
||||
|
||||
/* If VT is not NULL, write statistics for WHO into *VT.
|
||||
Return 0 for success, -1 for failure. */
|
||||
static int
|
||||
vtimes_one (struct vtimes *vt, enum __rusage_who who)
|
||||
{
|
||||
if (vt != NULL)
|
||||
{
|
||||
struct rusage usage;
|
||||
|
||||
if (__getrusage (who, &usage) < 0)
|
||||
return -1;
|
||||
|
||||
vt->vm_utime = TIMEVAL_TO_VTIMES (usage.ru_utime);
|
||||
vt->vm_stime = TIMEVAL_TO_VTIMES (usage.ru_stime);
|
||||
vt->vm_idsrss = usage.ru_idrss + usage.ru_isrss;
|
||||
vt->vm_majflt = usage.ru_majflt;
|
||||
vt->vm_minflt = usage.ru_minflt;
|
||||
vt->vm_nswap = usage.ru_nswap;
|
||||
vt->vm_inblk = usage.ru_inblock;
|
||||
vt->vm_oublk = usage.ru_oublock;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If CURRENT is not NULL, write statistics for the current process into
|
||||
*CURRENT. If CHILD is not NULL, write statistics for all terminated child
|
||||
processes into *CHILD. Returns 0 for success, -1 for failure. */
|
||||
int
|
||||
vtimes (current, child)
|
||||
struct vtimes *current;
|
||||
struct vtimes *child;
|
||||
{
|
||||
if (vtimes_one (current, RUSAGE_SELF) < 0
|
||||
|| vtimes_one (child, RUSAGE_CHILDREN) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user