Implementation of getrlimit and getdtablesize
This commit is contained in:
parent
26ba254a4a
commit
bd0933a19b
6 changed files with 127 additions and 0 deletions
|
@ -15,4 +15,32 @@
|
|||
int getpriority(int, int);
|
||||
int setpriority(int, int, int);
|
||||
|
||||
#ifdef _POSIX_SOURCE
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
typedef unsigned long rlim_t;
|
||||
|
||||
#define RLIM_INFINITY ((rlim_t) -1)
|
||||
#define RLIM_SAVED_CUR RLIM_INFINITY
|
||||
#define RLIM_SAVED_MAX RLIM_INFINITY
|
||||
|
||||
struct rlimit
|
||||
{
|
||||
rlim_t rlim_cur;
|
||||
rlim_t rlim_max;
|
||||
};
|
||||
|
||||
#define RLIMIT_CORE 1
|
||||
#define RLIMIT_CPU 2
|
||||
#define RLIMIT_DATA 3
|
||||
#define RLIMIT_FSIZE 4
|
||||
#define RLIMIT_NOFILE 5
|
||||
#define RLIMIT_STACK 6
|
||||
#define RLIMIT_AS 7
|
||||
|
||||
int getrlimit(int resource, struct rlimit *rlp);
|
||||
|
||||
#endif /* defined(_POSIX_SOURCE) */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -216,4 +216,8 @@ _PROTOTYPE( int initgroups, (const char *name, gid_t basegid) );
|
|||
|
||||
#endif
|
||||
|
||||
#ifdef _POSIX_SOURCE
|
||||
_PROTOTYPE( int getdtablesize, (void) );
|
||||
#endif
|
||||
|
||||
#endif /* _UNISTD_H */
|
||||
|
|
|
@ -77,6 +77,7 @@ libc_FILES=" \
|
|||
random.c \
|
||||
realpath.c \
|
||||
rindex.c \
|
||||
rlimit.c \
|
||||
setenv.c \
|
||||
setgroups.c \
|
||||
settimeofday.c \
|
||||
|
|
55
lib/other/rlimit.c
Normal file
55
lib/other/rlimit.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* getdtablesize, getrlimit Author: Erik van der Kouwe
|
||||
* query resource consumtion limits 4 December 2009
|
||||
*
|
||||
* Based on these specifications:
|
||||
* http://www.opengroup.org/onlinepubs/007908775/xsh/getdtablesize.html
|
||||
* http://www.opengroup.org/onlinepubs/007908775/xsh/getrlimit.html
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int getdtablesize(void)
|
||||
{
|
||||
return OPEN_MAX;
|
||||
}
|
||||
|
||||
int getrlimit(int resource, struct rlimit *rlp)
|
||||
{
|
||||
rlim_t limit;
|
||||
|
||||
switch (resource)
|
||||
{
|
||||
case RLIMIT_CORE:
|
||||
/* no core currently produced */
|
||||
limit = 0;
|
||||
break;
|
||||
|
||||
case RLIMIT_CPU:
|
||||
case RLIMIT_DATA:
|
||||
case RLIMIT_FSIZE:
|
||||
case RLIMIT_STACK:
|
||||
case RLIMIT_AS:
|
||||
/* no limit enforced (however architectural limits
|
||||
* may apply)
|
||||
*/
|
||||
limit = RLIM_INFINITY;
|
||||
break;
|
||||
|
||||
case RLIMIT_NOFILE:
|
||||
limit = OPEN_MAX;
|
||||
break;
|
||||
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* return limit */
|
||||
rlp->rlim_cur = limit;
|
||||
rlp->rlim_max = limit;
|
||||
return 0;
|
||||
}
|
||||
|
16
man/man3/getdtablesize.3
Normal file
16
man/man3/getdtablesize.3
Normal file
|
@ -0,0 +1,16 @@
|
|||
.TH GETDTABLESIZE 3 "December 4, 2009"
|
||||
.UC 4
|
||||
.SH NAME
|
||||
getdtablesize \- query maximum number of open files
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.ft B
|
||||
#include <unistd.h>
|
||||
|
||||
int getdtablesize(void);
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
getdtablesize returns the number of files that may be open at the same time
|
||||
in a process.
|
||||
.SH "RETURN VALUE
|
||||
The number of files that may be open at the same time in a process is returned.
|
23
man/man3/getrlimit.3
Normal file
23
man/man3/getrlimit.3
Normal file
|
@ -0,0 +1,23 @@
|
|||
.TH GETRLIMIT 3 "December 4, 2009"
|
||||
.UC 4
|
||||
.SH NAME
|
||||
getrlimit \- query resource consumption limits
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.ft B
|
||||
#include <sys/resource.h>
|
||||
|
||||
int getrlimit(int \fIresource\fP, struct rlimit *\fIrlp\fP);
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
getrlimit queries the current resource limit regarding the specified
|
||||
\fIresource\fP. This can be one of the following: RLIMIT_CORE, RLIMIT_CPU,
|
||||
RLIMIT_DATA, RLIMIT_FSIZE, RLIMIT_NOFILE, RLIMIT_STACK or RLIMIT_AS.
|
||||
The soft limit is specified in \fIrlp\fP\->rlim_cur and the hard limit in
|
||||
\fIrlp\fP\->rlim_max. On MINIX, these are currently always the same.
|
||||
A value of RLIM_INFINITY specifies that no limit is enforced, although
|
||||
architectural limits may still apply.
|
||||
.SH "RETURN VALUE
|
||||
If the function succeeds, 0 is returned.
|
||||
If the function fails, -1 is returned and errno is set to indicate the
|
||||
cause of the failure.
|
Loading…
Reference in a new issue