#include <stdio.h>
#include <sys/utsname.h> //uname int main(int argc, char **argv[])
{
struct utsname u;
if (uname(&u) != -1) {
printf("获取当前内核的名称和信息例如以下\n"
"sysname:%s\n"
"nodename:%s\n"
"release:%s\n"
"version:%s\n"
"machine:%s\n"
, u.sysname, u.nodename, u.release, u.version, u.machine);
} return 0;
}

输出例如以下:

获取当前内核的名称和信息例如以下
sysname:Linux
nodename:fes
release:2.6.32-220.el6.x86_64
version:#1 SMP Wed Nov 9 08:03:13 EST 2011
machine:x86_64

size_t confstr(int name, char *buf, size_t len);

confstr函数获取依赖配置的字符串变量的值

1、_CS_GNU_LIBC_VERSION,the GNU C library version on this system

2、_CS_GNU_LIBPTHREAD_VERSION,the POSIX implementation supplied by this C library

3、_CS_PATH,A value for the PATH variable which indicates where all the POSIX.2 standard utilities can be found.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> //confstr int main(int argc, char **argv[])
{
char *pathbuf, *gun_libpthread_version_buf, *gun_libc_version_buf;
size_t n; n = confstr(_CS_PATH,NULL,(size_t) 0);
pathbuf = malloc(n);
if (pathbuf == NULL)
abort();
confstr(_CS_PATH, pathbuf, n);
printf("_CS_PATH, A value for the PATH variable:%s\n", pathbuf);
free(pathbuf);
pathbuf = NULL; n = confstr(_CS_GNU_LIBPTHREAD_VERSION,NULL,(size_t) 0);
if (n > 0) {
gun_libpthread_version_buf = malloc(n);
}
if (gun_libpthread_version_buf == NULL)
abort();
confstr(_CS_GNU_LIBPTHREAD_VERSION, gun_libpthread_version_buf, n);
printf("_CS_GNU_LIBPTHREAD_VERSION, the POSIX implementation supplied by this C library:%s\n", gun_libpthread_version_buf);
free(gun_libpthread_version_buf);
gun_libpthread_version_buf = NULL; n = confstr(_CS_GNU_LIBC_VERSION,NULL,(size_t) 0);
if (n > 0) {
gun_libc_version_buf = malloc(n);
}
if (gun_libc_version_buf == NULL)
abort();
confstr(_CS_GNU_LIBC_VERSION, gun_libc_version_buf, n);
printf("_CS_GNU_LIBC_VERSION, the GNU C library version on this system: %s\n" \
, gun_libc_version_buf);
free(gun_libc_version_buf);
gun_libc_version_buf = NULL; return 0;
}

输出结果例如以下:

_CS_PATH, A value for the PATH variable:/bin:/usr/bin
_CS_GNU_LIBPTHREAD_VERSION, the POSIX implementation supplied by this C library:NPTL 2.12
_CS_GNU_LIBC_VERSION, the GNU C library version on this system: glibc 2.12

linux下confstr与uname函数_获取C库与内核信息的更多相关文章

  1. Linux下精确控制时间的函数

    Linux下精确控制时间的函数 在测试程序接口运行时间的时候,常用time,gettimeofday等函数,但是这些函数在程序执行的时候是耗费时间的,如果仅仅测试时间还行,但是如果程序中用到时间控制类 ...

  2. linux下时间有关的函数和结构体

    1.时间类型.Linux下常用的时间类型有6个:time_t,struct timeb, struct timeval,struct timespec,clock_t, struct tm. (1) ...

  3. Linux Linux下特殊的printf函数和fputs函数

    Linux下,printf函数必须以'\n'结尾才会立刻输出到屏幕,如果没有'\n'直到输出缓冲区满了以后才会打印到屏幕上(敲击换行也算),如果需要不换行的输出,一般可以使用write函数代替.'\n ...

  4. windows和linux下的本机IP的获取(亲测有效)

    package com.handsight.platform.fras.util; import org.apache.log4j.Logger; import javax.servlet.http. ...

  5. (转)linux下execl和system函数

    linux下,system函数和execl函数都是用于执行一条系统命令.今天仔细看了system函数的实现,想找出和execl函数的差别. 这里先进行一些背景知识补充: fork(创建一个新的进程): ...

  6. linux下c程序的链接、装载和库(1)

    读完<程序员的自我修养--链接.装载和库>相关章节,想来总结一下,若有错误,请指正,多谢. 1. 什么叫目标文件? 你的工程里有很多xxx.c这样的源文件,这些文件是文本文件,只有人能够认 ...

  7. linux下gcc默认搜索的头文件及库文件路径

    转自:https://blog.csdn.net/fd315063004/article/details/7925854 一.头文件 gcc 在编译时如何去寻找所需要的头文件:※所以header fi ...

  8. Linux下经常使用的C/C++开源Socket库

    1.      Linux Socket Programming In C++ : http://tldp.org/LDP/LG/issue74/tougher.html 2.      ACE: h ...

  9. Linux下经常使用的C/C++开源Socket库【转】

    转自:https://www.cnblogs.com/gccbuaa/p/7015599.html 1.      Linux Socket Programming In C++ : http://t ...

随机推荐

  1. 查询oracle数据库中当前数据库所有表的名称

    http://www.cnblogs.com/hyq0002013/p/5948419.html select t.table_name from user_tables t;

  2. 安装配置GitLab

    在 CentOS 6 安装 使用国内镜像安装,新建 /etc/yum.repos.d/gitlab-ce.repo,添加以下内容 [gitlab-ce] name=gitlab-ce baseurl= ...

  3. Qt笔记——QFile,QDataStream,QTextStream

    QFile #ifndef WIDGET_H #define WIDGET_H #include <QWidget> namespace Ui { class Widget; } clas ...

  4. Mysql的碎片查看与处理

    -- 每张表的大小 参考网址:http://www.oschina.net/question/12_3673 -- DATA_FREE 大于零表示有碎片 -- 在我们的项目中,生产环境一律采用独立的表 ...

  5. hdu5794

    从(u,v)到(n,m)相当于走x步1*2和y步2*1满足 x+2y=n-u,2x+y=m-v 解方程然后组合计数即可. 以前没写过lucas定理,写一下…… 其实就是C(n,m)%p=C(n/p,m ...

  6. (十一)mysql备份之物理备份xtrabackup

    (1)备份介绍 (2)下载安装xtrabackup 官网:https://www.percona.com/downloads/XtraBackup/LATEST/ 我选择yum安装,centos版本7 ...

  7. GridView的TemplateField

    BoundField只能显示一个单独的数据字段.如果我们想要在一个GridView列中显示两个或者更多的数据字段的值的时候该怎么办呢? 1. GridView的一列同时显示数据源中的两个字段 现需要显 ...

  8. Codeforces 811 B. Vladik and Complicated Book

    B. Vladik and Complicated Book   time limit per test 2 seconds memory limit per test 256 megabytes i ...

  9. HDU 4857 逃生 【拓扑排序+反向建图+优先队列】

    逃生 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...

  10. ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(第k短路模板)

    求第k短路模板 先逆向求每个点到终点的距离,再用dij算法,不会超时(虽然还没搞明白为啥... #include<iostream> #include<cstdio> #inc ...