Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 7.11 getrlimitandsetrlimitFunctions 223


implementations, we have conditionally included the resource names that differ.Note
that some systems definerlim_t to be an unsigned long long instead of an
unsigned long.This definition can even change on the same system, depending on
whether we compile the program to support 64-bit files. Some limits apply to file size,
so therlim_ttype has to be large enough to represent a file size limit. To avoid
compiler warnings that use the wrong format specification, we first copy the limit into a
64 - bit integer so that we have to deal with only one format.

#include "apue.h"
#include <sys/resource.h>
#define doit(name) pr_limits(#name, name)
static void pr_limits(char *, int);
int
main(void)
{
#ifdef RLIMIT_AS
doit(RLIMIT_AS);
#endif
doit(RLIMIT_CORE);
doit(RLIMIT_CPU);
doit(RLIMIT_DATA);
doit(RLIMIT_FSIZE);
#ifdef RLIMIT_MEMLOCK
doit(RLIMIT_MEMLOCK);
#endif
#ifdef RLIMIT_MSGQUEUE
doit(RLIMIT_MSGQUEUE);
#endif
#ifdef RLIMIT_NICE
doit(RLIMIT_NICE);
#endif
doit(RLIMIT_NOFILE);
#ifdef RLIMIT_NPROC
doit(RLIMIT_NPROC);
#endif
#ifdef RLIMIT_NPTS
doit(RLIMIT_NPTS);
#endif
#ifdef RLIMIT_RSS
doit(RLIMIT_RSS);
#endif
#ifdef RLIMIT_SBSIZE
doit(RLIMIT_SBSIZE);
Free download pdf