红联Linux门户
Linux帮助

程序判断Fedora的系统版本号

发布时间:2007-08-26 22:03:30来源:红联作者:Wisdom
因为程序中要用到判断程序所在运行的操作系统是Fedora哪个版本的,所以找了这个函数。

/* Structure describing the system and machine. */
struct utsname
{
/* Name of the implementation of the operating system. */
char sysname[_UTSNAME_SYSNAME_LENGTH];

/* Name of this node on the network. */
char nodename[_UTSNAME_NODENAME_LENGTH];

/* Current release level of this implementation. */
char release[_UTSNAME_RELEASE_LENGTH];
/* Current version level of this release. */
char version[_UTSNAME_VERSION_LENGTH];

/* Name of the hardware type the system is running on. */
char machine[_UTSNAME_MACHINE_LENGTH];
};
/* Put information about the system in NAME. */
extern int uname (struct utsname *name);


这个函数和命令中的uname一样的功能,可以得到系统的标识,ustsname结构中release得到的是内核的版本号,它的基本格式就是2.*.*-*.*.fc* 最后三个字符一般就是我要的版本号了。

在RH9中也是有这个函数的(基本上几个中系统应该都有的)只这它得到的release没有最后三个字符的。
文章评论

共有 0 条评论