1 /* getrlimit Author: Erik van der Kouwe 2 * query resource consumtion limits 4 December 2009 3 * 4 * Based on these specifications: 5 * http://www.opengroup.org/onlinepubs/007908775/xsh/getdtablesize.html 6 * http://www.opengroup.org/onlinepubs/007908775/xsh/getrlimit.html 7 */ 8 9 #include <sys/cdefs.h> 10 #include "namespace.h" 11 12 #include <errno.h> 13 #include <limits.h> 14 #include <sys/resource.h> 15 #include <unistd.h> 16 17 int getrlimit(int resource, struct rlimit *rlp) 18 { 19 rlim_t limit; 20 21 switch (resource) 22 { 23 case RLIMIT_CPU: 24 case RLIMIT_FSIZE: 25 case RLIMIT_DATA: 26 case RLIMIT_STACK: 27 case RLIMIT_CORE: 28 case RLIMIT_RSS: 29 case RLIMIT_MEMLOCK: 30 case RLIMIT_NPROC: 31 case RLIMIT_SBSIZE: 32 case RLIMIT_AS: 33 /* case RLIMIT_VMEM: Same as RLIMIT_AS */ 34 case RLIMIT_NTHR: 35 /* no limit enforced (however architectural limits 36 * may apply) 37 */ 38 limit = RLIM_INFINITY; 39 break; 40 41 case RLIMIT_NOFILE: 42 limit = OPEN_MAX; 43 break; 44 45 default: 46 errno = EINVAL; 47 return -1; 48 } 49 50 /* return limit */ 51 rlp->rlim_cur = limit; 52 rlp->rlim_max = limit; 53 return 0; 54 } 55 56