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_SBSIZE: 31 case RLIMIT_AS: 32 /* case RLIMIT_VMEM: Same as RLIMIT_AS */ 33 case RLIMIT_NTHR: 34 /* no limit enforced (however architectural limits 35 * may apply) 36 */ 37 limit = RLIM_INFINITY; 38 break; 39 40 case RLIMIT_NPROC: 41 limit = CHILD_MAX; 42 break; 43 44 case RLIMIT_NOFILE: 45 limit = OPEN_MAX; 46 break; 47 48 default: 49 errno = EINVAL; 50 return -1; 51 } 52 53 /* return limit */ 54 rlp->rlim_cur = limit; 55 rlp->rlim_max = limit; 56 return 0; 57 } 58 59