-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystemInfo.c
73 lines (63 loc) · 1.99 KB
/
SystemInfo.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/resource.h>
#include <sys/statvfs.h>
void print_cpu_info() {
long num_processors = sysconf(_SC_NPROCESSORS_CONF);
printf("Number of Processors: %ld\n", num_processors);
}
void print_memory_info() {
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
long total_memory = pages * page_size / (1024 * 1024); // Convert to MB
printf("Total Memory: %ld MB\n", total_memory);
}
void print_disk_info() {
struct statvfs stat;
if (statvfs("/", &stat) == 0) {
long block_size = stat.f_frsize;
long total_blocks = stat.f_blocks;
long total_space = total_blocks * block_size / (1024 * 1024 * 1024); // Convert to GB
printf("Total Disk Space: %ld GB\n", total_space);
}
}
void print_load_average() {
double loadavg[3];
if (getloadavg(loadavg, 3) != -1) {
printf("Load Average (1min, 5min, 15min): %.2f, %.2f, %.2f\n",
loadavg[0], loadavg[1], loadavg[2]);
}
}
void print_user_limits() {
struct rlimit rlim;
if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
printf("Maximum number of open files: %ld\n", rlim.rlim_cur);
}
}
int main() {
struct utsname unameData;
// Get system information
if (uname(&unameData) != 0) {
perror("uname");
return EXIT_FAILURE;
}
// Print basic system information
printf("System Information:\n");
printf(" OS: %s %s\n", unameData.sysname, unameData.release);
printf(" Node Hostname: %s\n", unameData.nodename);
printf(" OS Version: %s\n", unameData.version);
printf(" Machine Type: %s\n", unameData.machine);
// Print advanced system information
printf("\nAdvanced System Information:\n");
print_cpu_info();
print_memory_info();
print_disk_info();
print_load_average();
print_user_limits();
return EXIT_SUCCESS;
}