#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. 作业执行器Job Executor

    Job Executor 激活作业执行器 AsyncExecutor是一个组件,它管理线程池,来触发计时器和其他异步任务.其他实现也是可能的(例如使用消息队列,请参阅用户指南的高级部分). 默认情况下 ...

  2. apt-get常用命令及工作原理

    https://blog.csdn.net/mosquito_zm/article/details/63684608

  3. 在Ubuntu 16.04安装 Let’s Encrypt并配置ssl

    1.安装前准备 1)要确保python的默认版本为2.7及以上版本. 2)需要配置的apache.nginx需要提前配置绑定域名. 2.安装ssl 在这个https://certbot.eff.org ...

  4. django static文件的引入方式(转)

    1. 在django project中创建 static文件夹 2.settings.py中配置要在 STATIC_URL = '/static/'  下边 STATICFILES_DIRS = [ ...

  5. django URL参数在view中传递和Template的反向解析方式

    一. URL参数在view中传递 1.带参数名:通过named group方式传递指定参数,语法为: (?P<name>pattern), name 为传递参数的名称,pattern代表所 ...

  6. Error converting bytecode to dex: Cause: java.lang.RuntimeException: Exception parsing classes

    http://blog.csdn.net/xx326664162/article/details/51859106 总算有个靠谱的了

  7. HDU 多校1.12

  8. java 时间格式化中的模式字母

    java日期格式化中的模式字母有特定的意义,由于没有注意,今天在做工程的时候导致出现了奇怪的日期: 错误写法如下: 然而得到了错误的结果: 正确写法如下: 这样就得到了正确的结果 mm指的是分钟,MM ...

  9. 福州三中集训day3

    Day3数据结构,强无敌. 基本讲的是栈,队列,链表,都是些还会的操作,然后接着讲的就比较心凉凉了,先讲了堆,然后是hsah 栈,队列,链表问题都不大,笔记记得都还好,堆就凉凉了. 不会不会不会,没学 ...

  10. 洛谷——P2556 [AHOI2002]黑白图像压缩

    P2556 [AHOI2002]黑白图像压缩 题目描述 选修基础生物基因学的时候, 小可可在家里做了一次图像学试验. 她知道:整个图像其实就是若干个图像点(称作像素)的序列,假定序列中像素的个数总是 ...