如何在C ++中读取系统信息? [英] How do I read system information in C++?

查看:122
本文介绍了如何在C ++中读取系统信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在C ++中的Linux系统上获取操作系统版本,硬盘空间,可用磁盘空间和安装的RAM等信息。我知道我可以使用 system()运行不同的Linux命令和捕获他们的输出(这是我目前在做),但我想知道是否有一个更好的方法?

I'm trying to get information like OS version, hard disk space, disk space available, and installed RAM on a Linux system in C++. I know I can use system() to run different Linux commands and capture their output (which is what I'm currently doing) but I was wondering if there's a better way? Is there something in the C++ standard library that I can use to get information from the operating system?

推荐答案

如果你使用的是*

If you are using *nix commands via system.

然后,男人滚动到手机页面的底部,它通常会显示与什么相关的C系统调用是相关的。 p>

Then do man scroll to the bottom of the man page and it will usually show you what relevant C system calls are related.

Example:  man uname:
SEE ALSO
       uname(2), getdomainname(2), gethostname(2)


Explanation of numbers:

(1): User UNIX Command
(2): Unix and C system calls
(3): C Library routines
(4): Special file names
(5): File formats
(6): 
(7):
(8): System admin commands

所以如果你使用system(uname)。从手册页可以看到,还有一个uname C系统调用(uname(2))。所以你现在可以做一个man 2 uname来获取关于如何使用C系统调用uname的信息。

So if you are using system("uname"). From the man page you can see that there is also a uname C system call (uname(2)). So you can now do a 'man 2 uname' to get information about how to use the C system call uname.

这篇关于如何在C ++中读取系统信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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