In most of the Linux systems we use the command “uname” to print the system information in the terminal.
which gives the information about the system such as OS name, kernel version, release,domain name etc... Similerly we can get that information through C Programming.
Now I will let you how to print Linux system information through C programming in Linux, by using the structure “struct utsname”, and the system call uname() which return 0 on success, -1 on error.. See the code snnippet given below...
struct utsname buf;
ret = uname(&buf);
printf("OperatingSystem name: %s\n",buf.sysname);
printf("Node(Host) name: %s\n",buf.nodename);
printf("Kernel Release Version: %s\n",buf.release);
printf("OS Version: %s\n",buf.version);
printf("Error in the System call");
OperatingSystem name: Linux
Node(Host) name: SAI-LAP
Kernel Release Version: 3.2.0-32-generic-pae
OS Version: #51-Ubuntu SMP Wed Sep 26 21:54:23 UTC 2012
Note: We can also access these details through /proc/sys/kernel directory, for example
which gives Operating system type...similerly we can get osrelease,hostname,version,domainname (replace “ostype” with any of these).