C如何使用函数uname [英] C how to use the function uname

查看:46
本文介绍了C如何使用函数uname的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该编写一个函数来获取有关系统的一些信息(最重要的信息是体系结构).我找到了可以使用的功能 uname ,其中包括 sys/utsname.h .好吧,尽管我用Google搜索并阅读了文档,但找不到该函数的任何示例,而且我不知道如何使用uname.有人可以向我解释如何使用它吗?如果您也可以写一个示例,那将是很棒的.预先感谢.

I should write a function to get some information about the system (the most important information is the the architecture). I found the function uname which can be used including sys/utsname.h. Well, though I googled and I read the documentation, I couldn't find any example of the function and I don't understand how to use uname. Anyone can explain me how to use it? it would be great if you can write an example, too. Thanks in advance.

推荐答案

首先,添加标题:

#include <sys/utsname.h>

然后,定义一个utsname结构:

Then, define a utsname structure:

struct utsname unameData;

然后,使用指向该结构的指针调用uname():

Then, call uname() with a pointer to the struct:

uname(&unameData); // Might check return value here (non-0 = failure)

此后,结构将包含您想要的信息:

After this, the struct will contain the info you want:

printf("%s", unameData.sysname);

http://opengroup.org/onlinepubs/007908775/xsh/sysutsname.h.html

这篇关于C如何使用函数uname的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆