You can simply use the function:
int uname(struct utsname *buf);
by including the header
#include <sys/utsname.h>
It already returns the name & version as a part of the structure:
struct utsname
{
char sysname[]; /* Operating system name (e.g., "Linux") */
char nodename[]; /* Name within "some implementation-defined network" */
char release[]; /* OS release (e.g., "2.6.28") */
char version[]; /* OS version */
char machine[]; /* Hardware identifier */
#ifdef _GNU_SOURCE
char domainname[]; /* NIS or YP domain name */
#endif
};
Am I missing something?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…