使用C获取操作系统名称[Linux,可移植的发行版:Centos,Debian,Fedora,OpenSUSE,RedHat,Ubuntu] [英] Get OS name with C [Linux, portable for distros: Centos, Debian, Fedora, OpenSUSE, RedHat, Ubuntu]

查看:298
本文介绍了使用C获取操作系统名称[Linux,可移植的发行版:Centos,Debian,Fedora,OpenSUSE,RedHat,Ubuntu]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用以下简单命令检查我的操作系统名称:lsb_release -ds.但是我也知道,它不能在我需要的所有平台上移植.我尝试了struct utsname info;uname(&info),效果很好,但只给了我一个基本"名称-"Linux".

I know I can check my OS name with this simple command: lsb_release -ds. But I also know, that its not portable on all platforms where I need it. I tried struct utsname info; and uname(&info) and it works great but gives me only "base" name - "Linux".

是否有任何便携式(C)方式来获得完整的操作系统名称?至少在Centos,Debian,Fedora,OpenSUSE,RedHat,Ubuntu之间可移植?干杯

Is there any portable (C) way of getting full OS name? Portable between Centos, Debian, Fedora, OpenSUSE, RedHat, Ubuntu at least? Cheers

推荐答案

uname系统调用在sysname字段中为您提供了通用系统类型(在所有情况下为Linux),但同时也为您提供了releaseversionmachine字段中的其他数据. release字段将为您提供内核版本,而version字段将为您提供常规系统版本,对于您提到的所有各种Linux变体,该版本都会有所不同.

The uname system call gives you the generic system type (Linux in all your cases) in the sysname field, but it also gives you additional data in the release, version, and machine fields. The release field will give you the kernel version, and the version field will give you the general system version, which will be different for all the various linux variants you mention.

这篇关于使用C获取操作系统名称[Linux,可移植的发行版:Centos,Debian,Fedora,OpenSUSE,RedHat,Ubuntu]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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