linux c获取系统信息

来源:互联网 发布:哈密顿算法 编辑:程序博客网 时间:2024/06/05 06:05
/*
 ============================================================================
 Name        : Demo.c
 Author      : jwang
 Version     :
 Copyright   : Your copyright notice
 Description : System information in C, Ansi-style
 ============================================================================
 */

#include <sys/utsname.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(void) {

    char computer[256];
    struct utsname uts;

    if(gethostname(computer, 255) != 0 || uname(&uts) < 0){
        fprintf(stderr, "could not get host information\n");
    }

    printf("computer host name is %s\n", computer);
    printf("system is %s on %s hardware\n", uts.sysname, uts.machine);
    printf("nodeName is %s\n", uts.nodename);
    printf("version is %s, %s\n", uts.release, uts.version);

    return 0;
}


原创粉丝点击