-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path002.c
More file actions
65 lines (54 loc) · 2.43 KB
/
002.c
File metadata and controls
65 lines (54 loc) · 2.43 KB
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
55
56
57
58
59
60
61
62
63
64
65
/*
..........................................................................................................................................
Name : 002.c
Author : SHRUTI VERMA
Description : Write a program to print the system resource limits. Use getrlimit system call.
Date : 29 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/resource.h>
void print_limit(int resource, const char *name) {
struct rlimit rl;
(getrlimit(resource, &rl) == 0);
long int soft = (long) rl.rlim_cur;
long int hard = (long) rl.rlim_max;
printf("%-20s Soft Limit : ", name);
if(soft == RLIM_INFINITY)
printf("UNLIMITED\t");
else printf("%ld \t", soft);
printf("Hard Limit : ");
if(hard == RLIM_INFINITY)
printf("UNLIMITED\n");
else printf("%ld\n", hard);
//printf("%-20s: Soft limit = %ld, Hard limit = %ld\n", name, soft, hard);
}
int main() {
print_limit(RLIMIT_CPU, "CPU Time");
print_limit(RLIMIT_FSIZE, "File Size");
print_limit(RLIMIT_DATA, "Data Segment Size");
print_limit(RLIMIT_STACK, "Stack Size");
print_limit(RLIMIT_CORE, "Core File Size");
print_limit(RLIMIT_RSS, "Resident Set Size");
print_limit(RLIMIT_NOFILE, "Number of Open Files");
print_limit(RLIMIT_AS, "Address Space Size");
print_limit(RLIMIT_NPROC, "Number of Processes");
print_limit(RLIMIT_MEMLOCK, "Locked Memory Size");
print_limit(RLIMIT_LOCKS, "File Locks");
return 0;
}
/*--------------------------------_OUTPUT------------------------------------------------------
CPU Time Soft Limit : UNLIMITED Hard Limit : UNLIMITED
File Size Soft Limit : UNLIMITED Hard Limit : UNLIMITED
Data Segment Size Soft Limit : UNLIMITED Hard Limit : UNLIMITED
Stack Size Soft Limit : 8388608 Hard Limit : UNLIMITED
Core File Size Soft Limit : 0 Hard Limit : UNLIMITED
Resident Set Size Soft Limit : UNLIMITED Hard Limit : UNLIMITED
Number of Open Files Soft Limit : 1048576 Hard Limit : 1048576
Address Space Size Soft Limit : UNLIMITED Hard Limit : UNLIMITED
Number of Processes Soft Limit : 30107 Hard Limit : 30107
Locked Memory Size Soft Limit : 1025282048 Hard Limit : 1025282048
File Locks Soft Limit : UNLIMITED Hard Limit : UNLIMITED
*/