#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. 存储过程 ----- navicat 创建存储过程

    以下为navicat 创建存储过程步骤图解: 1. 2. 3. 4. 在存储过程正文中是输入一行语句测试用,点击保存 5.输入存储过程名称,点击确定 6.到这来那么问题来了,会提示错误 7.切记存储过 ...

  2. Jxl、JxCell图表导出功能的实现

    最近接触过许多报表导出功能,也用过多种工具进行导出功能的实现,但对于图表的导出一直没有仔细的去展开研究和探讨,直到最近略微整理了下这方面的需求和技术攻克. 首先导出excel功能的实现主要有JXL.J ...

  3. docker 安装持久化mysql

    https://hub.docker.com 拉取mysql镜像docker pull mysql:5.5运行mysql镜像并持久化到本地docker run -v /var/own/mysqldat ...

  4. 内存可见性,指令重排序,JIT。。。。。。从一个知乎问题谈起

    在知乎上看到一个问题<java中volatile关键字的疑惑?>,引起了我的兴趣 问题是这样的: package com.cc.test.volatileTest; public clas ...

  5. C、C++ static 的作用

    1.隐藏 当同时编译多个文件时,所有未加static关键字的全局变量和函数都具有全局可见性. 例如:同时编译两个源文件 //ghz.c #include <stdio.h> char a ...

  6. kotlin 写的一个简单 sql 查询解析器

    package com.dx.efuwu.core import org.apache.commons.lang.StringUtils import java.sql.PreparedStateme ...

  7. HDU 1159.Common Subsequence-最长公共子序列(LCS)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. Codeforces 189A. Cut Ribbon

    题目链接:http://codeforces.com/problemset/problem/189/A 题意: 给你一个长度为 N 的布条, 再给你三个长度 a, b , c.你可以用剪刀去剪这些布条 ...

  9. 训练指南 UVALive - 3523 (双联通分量 + 二分图染色)

    layout: post title: 训练指南 UVALive - 3523 (双联通分量 + 二分图染色) author: "luowentaoaa" catalog: tru ...

  10. dutacm.club 1094: 等差区间(RMQ区间最大、最小值,区间GCD)

    1094: 等差区间 Time Limit:5000/3000 MS (Java/Others)   Memory Limit:163840/131072 KB (Java/Others)Total ...