#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Function to report kernel version
void report_kernel_info( ) {
FILE * file = fopen ( "/proc/version" , "r" ) ; // Open the file with kernel version info
if ( file == NULL ) { // Check if file opened successfully
perror ( "Failed to open /proc/version" ) ;
exit ( EXIT_FAILURE ) ;
}
char line[ 256 ] ;
if ( fgets ( line, sizeof ( line) , file) ) { // Read the first line
printf ( "Kernel Version: %s" , line) ; // Print kernel version
}
fclose ( file) ; // Close the file
}
// Function to report CPU details
void report_cpu_info( ) {
FILE * file = fopen ( "/proc/cpuinfo" , "r" ) ; // Open the file with CPU info
if ( file == NULL ) { // Check if file opened successfully
perror ( "Failed to open /proc/cpuinfo" ) ;
exit ( EXIT_FAILURE ) ;
}
char line[ 256 ] ;
char cpu_model[ 256 ] = "Unknown" ; // Placeholder for CPU model
char cpu_architecture[ 256 ] = "Unknown" ; // Placeholder for CPU architecture
while ( fgets ( line, sizeof ( line) , file) ) { // Read file line by line
if ( strncmp ( line, "model name" , 10 ) == 0 ) { // Check for CPU model
sscanf ( line, "model name\t : %[^\n ]" , cpu_model) ;
}
if ( strncmp ( line, "architecture" , 12 ) == 0 ) { // Check for CPU architecture
sscanf ( line, "architecture\t : %[^\n ]" , cpu_architecture) ;
}
}
fclose ( file) ; // Close the file
printf ( "CPU Type: %s\n " , cpu_model) ; // Print CPU model
printf ( "CPU Architecture: %s\n " , cpu_architecture) ; // Print CPU architecture
}
int main( ) {
printf ( "System Information Report\n " ) ;
printf ( "------------------------------\n " ) ;
report_kernel_info( ) ; // Call function to display kernel version
report_cpu_info( ) ; // Call function to display CPU details
printf ( "------------------------------\n " ) ;
return 0 ; // Exit program
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKLy8gRnVuY3Rpb24gdG8gcmVwb3J0IGtlcm5lbCB2ZXJzaW9uCnZvaWQgcmVwb3J0X2tlcm5lbF9pbmZvKCkgewogICAg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