美文网首页
uname函数获取系统信息

uname函数获取系统信息

作者: 一路向后 | 来源:发表于2020-07-27 21:24 被阅读0次

    1.程序源码

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/utsname.h>
    #include <errno.h>
    
    int main()
    {
        struct utsname buffer;
    
        if(uname(&buffer) != 0)
        {
            perror("uname");
            return -1;
        }
    
        printf("操作系统:\t%s\n", buffer.sysname);
        printf("网络主机名\t%s\n", buffer.nodename);
        printf("当前发布级别:\t%s\n", buffer.release);
        printf("当前发布版本:\t%s\n", buffer.version);
        printf("CPU架构:\t%s\n", buffer.machine);
        printf("域名:\t\t%s\n", buffer.__domainname);
    
        return 0;
    }
    

    2.编译源码

    $ gcc -o uname uname.c
    

    3.运行程序

    $ ./uname
    操作系统:   Linux
    网络主机名:  tom-desktop
    当前发布级别: 3.4.6-r2
    当前发布版本: #1 SMP Thu Sep 20 14:40:51 UTC 2012
    CPU架构:  i686
    域名:     (none)
    

    相关文章

      网友评论

          本文标题:uname函数获取系统信息

          本文链接:https://www.haomeiwen.com/subject/osvtrktx.html