-
Notifications
You must be signed in to change notification settings - Fork 307
/
limits.c
executable file
·54 lines (46 loc) · 1.21 KB
/
limits.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void work()
{
FILE *f;
int i;
double x = 4.5;
f = tmpfile();
for (i = 0; i < 10000; i++) {
fprintf(f, "Do some output\n");
if (ferror(f)) {
fprintf(stderr, "Error writing to tempoary file\n");
exit(1);
}
}
for (i = 0; i < 1000000; i++) {
x = x * x + 3.21;
}
}
int main()
{
struct rusage r_usage;
struct rlimit r_limit;
int priority;
work();
getrusage(RUSAGE_SELF, &r_usage);
printf("CPU usage: User = %ld.%06ld, System = %ld.%06ld\n",
r_usage.ru_utime.tv_sec, r_usage.ru_utime.tv_usec,
r_usage.ru_stime.tv_sec, r_usage.ru_stime.tv_usec );
priority = getpriority(PRIO_PROCESS, getpid());
printf("Current priority = %d\n", priority);
getrlimit(RLIMIT_FSIZE, &r_limit);
printf("Current FSIZE limit: soft = %ld, hard = %ld\n",
r_limit.rlim_cur, r_limit.rlim_max);
r_limit.rlim_cur = 2048;
r_limit.rlim_max = 4096;
printf("Setting a 2K file size limit\n");
setrlimit(RLIMIT_FSIZE, &r_limit);
work();
exit(0);
}