1 // rlimit should be able to set file limits
6 #include <sys/resource.h>
11 static const long lim
= 42;
12 static const int r
= RLIMIT_NOFILE
;
18 if (setrlimit(r
, &rl
))
19 t_error("setrlimit(%d, %ld) failed: %s\n", r
, lim
, strerror(errno
));
20 if (getrlimit(r
, &rl
))
21 t_error("getrlimit(%d) failed: %s\n", r
, strerror(errno
));
22 if (rl
.rlim_max
!= lim
|| rl
.rlim_cur
!= lim
)
23 t_error("getrlimit %d says cur=%ld,max=%ld after setting the limit to %ld\n", r
, rl
.rlim_cur
, rl
.rlim_max
, lim
);
25 while((fd
=dup(1)) != -1)
26 if (fd
> maxfd
) maxfd
= fd
;
28 t_error("dup(1) failed with %s, wanted EMFILE\n", strerror(errno
));
30 t_error("more fds are open than rlimit allows: fd=%d, limit=%d\n", maxfd
, lim
);