linux下confstr与uname函数_获取C库与内核信息
#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库与内核信息的更多相关文章
- Linux下精确控制时间的函数
Linux下精确控制时间的函数 在测试程序接口运行时间的时候,常用time,gettimeofday等函数,但是这些函数在程序执行的时候是耗费时间的,如果仅仅测试时间还行,但是如果程序中用到时间控制类 ...
- linux下时间有关的函数和结构体
1.时间类型.Linux下常用的时间类型有6个:time_t,struct timeb, struct timeval,struct timespec,clock_t, struct tm. (1) ...
- Linux Linux下特殊的printf函数和fputs函数
Linux下,printf函数必须以'\n'结尾才会立刻输出到屏幕,如果没有'\n'直到输出缓冲区满了以后才会打印到屏幕上(敲击换行也算),如果需要不换行的输出,一般可以使用write函数代替.'\n ...
- windows和linux下的本机IP的获取(亲测有效)
package com.handsight.platform.fras.util; import org.apache.log4j.Logger; import javax.servlet.http. ...
- (转)linux下execl和system函数
linux下,system函数和execl函数都是用于执行一条系统命令.今天仔细看了system函数的实现,想找出和execl函数的差别. 这里先进行一些背景知识补充: fork(创建一个新的进程): ...
- linux下c程序的链接、装载和库(1)
读完<程序员的自我修养--链接.装载和库>相关章节,想来总结一下,若有错误,请指正,多谢. 1. 什么叫目标文件? 你的工程里有很多xxx.c这样的源文件,这些文件是文本文件,只有人能够认 ...
- linux下gcc默认搜索的头文件及库文件路径
转自:https://blog.csdn.net/fd315063004/article/details/7925854 一.头文件 gcc 在编译时如何去寻找所需要的头文件:※所以header fi ...
- Linux下经常使用的C/C++开源Socket库
1. Linux Socket Programming In C++ : http://tldp.org/LDP/LG/issue74/tougher.html 2. ACE: h ...
- Linux下经常使用的C/C++开源Socket库【转】
转自:https://www.cnblogs.com/gccbuaa/p/7015599.html 1. Linux Socket Programming In C++ : http://t ...
随机推荐
- sql参数化防止sql注入导致的暴露数据库问题
#转载请联系 假如你在京东工作,你要做的任务就是做一个商品搜索的东西供用户使用. 然后你写出了这么一个程序的雏形. import pymysql def main(): conn = pymysql. ...
- native,strictfp,transient,volatile什么java?
1. native 簡單講,呼叫其他語言(c,c++之類)做出來的dll做法1.利用java做個介面供其他語言實作(也就是宣告成native)2.用javah產出.h:3.用其他語言實現native方 ...
- ubantu16.04服务器错误提示没有安装php_fileinfo扩展
如果你是安装的LNMP1.3full一键安装包,安装的是php5.6.22,你会遇到这个错误,解决方法也不难,请看如下: 不需要去下载扩展,只需要进入此fileinfo目录(我这里有多个版本5.6,7 ...
- C# axWindowsMediaPlayer制作播放器
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- [libGDX游戏开发教程]使用libGDX进行游戏开发(12)-Action动画
前文章节列表: 使用libGDX进行游戏开发(11)-高级编程技巧 使用libGDX进行游戏开发(10)-音乐音效不求人,程序员也可以DIY 使用libGDX进行游戏开发(9)-场景过渡 ...
- 漫谈网络通信——从OSI网络模型到TCP/IP协议族
OSI七层模型 OSI(Open System Interconnection,开放系统互联)七层网络模型成为开放式系统互联参考模型,是一个把网络通信在逻辑上的定义,也可以理解成为定义了通用的网络通信 ...
- Centos7源码编译安装tengine1.5.1
安装依赖包 yum install pcre pcre-devel openssl openssl-devel gcc make zlib-devel wget -y 下载和创建用户 mkdir /t ...
- 【cocos2d-js官方文档】七、CCFileUtils
Web引擎 CCFileUtils.js在Web引擎中已经被删除了,原因是FileUtils在原生平台中的文件检索功能在Web端是无法实现的. 二进制文件获取的方法被转移到了cc.loader.loa ...
- [php] 解析JSON字符串
$json_str = '{"thumb":"","photo":[{"url":"557a3d2184db0 ...
- tensorflow-gpu 使用的常见错误
这篇博客会不定期整理我在 tensorflow 中出现的问题和坑. 1. CUDA_ERROR_OUT_OF_MEMORY: tensorflow 在执行过程中会默认使用全部的 GPU 内存,给系统保 ...