fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. // Function to report kernel version
  6. void report_kernel_info() {
  7. FILE *file = fopen("/proc/version", "r"); // Open the file with kernel version info
  8. if (file == NULL) { // Check if file opened successfully
  9. perror("Failed to open /proc/version");
  10. exit(EXIT_FAILURE);
  11. }
  12.  
  13. char line[256];
  14. if (fgets(line, sizeof(line), file)) { // Read the first line
  15. printf("Kernel Version: %s", line); // Print kernel version
  16. }
  17. fclose(file); // Close the file
  18. }
  19.  
  20. // Function to report CPU details
  21. void report_cpu_info() {
  22. FILE *file = fopen("/proc/cpuinfo", "r"); // Open the file with CPU info
  23. if (file == NULL) { // Check if file opened successfully
  24. perror("Failed to open /proc/cpuinfo");
  25. exit(EXIT_FAILURE);
  26. }
  27.  
  28. char line[256];
  29. char cpu_model[256] = "Unknown"; // Placeholder for CPU model
  30. char cpu_architecture[256] = "Unknown"; // Placeholder for CPU architecture
  31.  
  32. while (fgets(line, sizeof(line), file)) { // Read file line by line
  33. if (strncmp(line, "model name", 10) == 0) { // Check for CPU model
  34. sscanf(line, "model name\t: %[^\n]", cpu_model);
  35. }
  36. if (strncmp(line, "architecture", 12) == 0) { // Check for CPU architecture
  37. sscanf(line, "architecture\t: %[^\n]", cpu_architecture);
  38. }
  39. }
  40. fclose(file); // Close the file
  41.  
  42. printf("CPU Type: %s\n", cpu_model); // Print CPU model
  43. printf("CPU Architecture: %s\n", cpu_architecture); // Print CPU architecture
  44. }
  45.  
  46. int main() {
  47. printf("System Information Report\n");
  48. printf("------------------------------\n");
  49. report_kernel_info(); // Call function to display kernel version
  50. report_cpu_info(); // Call function to display CPU details
  51. printf("------------------------------\n");
  52. return 0; // Exit program
  53. }
  54.  
  55.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
System Information Report
------------------------------
Kernel Version: Linux version 6.1.0-13-amd64 (debian-kernel@lists.debian.org) (gcc-12 (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1 SMP PREEMPT_DYNAMIC Debian 6.1.55-1 (2023-09-29)
CPU Type: Intel(R) Xeon(R) CPU E3-1270 V2 @ 3.50GHz
CPU Architecture: Unknown
------------------------------