#include"stdio.h" #include"sys/utsname.h" intmain(){ structutsnameuts; /* Put information about the system in NAME. */ uname(&uts); printf("name=%s\n",uts.sysname); printf("version=%s\n",uts.version); printf("release=%s\n",uts.release); printf("nodename=%s\n",uts.nodename); printf("machine=%s\n",uts.machine); return0; }
/**out: name=Linux version=#29~20.04.1-Ubuntu SMP Mon Aug 01 20:58:17 UTC 2021 release=5.11.0-27-generic nodename=longtaoXiaoXinPro13-2020 machine=x86_64 **/
structutsname { /* Name of the implementation of the operating system. */ char sysname[_UTSNAME_SYSNAME_LENGTH];
/* Name of this node on the network. */ char nodename[_UTSNAME_NODENAME_LENGTH];
/* Current release level of this implementation. */ char release[_UTSNAME_RELEASE_LENGTH]; /* Current version level of this release. */ char version[_UTSNAME_VERSION_LENGTH];
/* Name of the hardware type the system is running on. */ char machine[_UTSNAME_MACHINE_LENGTH];
#if _UTSNAME_DOMAIN_LENGTH - 0 /* Name of the domain of this node on the network. */ # ifdef __USE_GNU char domainname[_UTSNAME_DOMAIN_LENGTH]; # else char __domainname[_UTSNAME_DOMAIN_LENGTH]; # endif #endif };
通过文件查看
内核信息
1
cat /proc/version
发行信息
简要
1
cat /etc/issue
完整
1
cat /etc/*-release
CPU信息
lscpu命令或
1
cat /proc/cpuinfo
除此之外还可以获取一些其他信息
1 2 3 4 5 6 7 8
longtao@longtaoXiaoXinPro13-2020:~$ ls /proc|grep info buddyinfo cpuinfo meminfo pagetypeinfo slabinfo vmallocinfo zoneinfo