C++ get linux distribution name\version

后端 未结 6 1639
悲哀的现实
悲哀的现实 2021-01-12 06:10

According to the question \" How to get Linux distribution name and version? \", to get the linux distro name and version, this works:

lsb_release -a
         


        
6条回答
  •  情歌与酒
    2021-01-12 06:51

    You can simply use the function:

    int uname(struct utsname *buf);
    

    by including the header

    #include 
    

    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?

提交回复
热议问题