linux struct utsname 結構詳解

來源:互聯網
上載者:User

【uname系統調用】

功能描述:
擷取當前核心名稱和其它資訊。
用法:
#include <sys/utsname.h>
extern int uname (struct utsname *__name) __THROW;
The <sys/utsname.h> header defines structure utsname, which includes atleast the following members:

char sysname[]  name of thisimplementation of the operating system

char nodename[] name of this node within an implementation-dependent communicationsnetwork

char release[]  current release levelof this implementation

char version[]  current version levelof this release

char machine[]  name of the hardwaretype on which the system is running

The character arrays are of unspecifiedsize, but the data stored in them is terminated by a null byte.

The following is declared as a functionand may also be defined as a macro.
參數:
__name:指向存放系統資訊的緩衝區,原型如下
struct utsname
{ char sysname[_UTSNAME_SYSNAME_LENGTH];//當前作業系統名
char nodename[_UTSNAME_NODENAME_LENGTH];//網路上的名稱
char release[_UTSNAME_RELEASE_LENGTH];//當前發布層級
char version[_UTSNAME_VERSION_LENGTH];//當前發布版本
char machine[_UTSNAME_MACHINE_LENGTH];//當前硬體體系類型
#if _UTSNAME_DOMAIN_LENGTH - 0
/* Name of the domain of this node on the network. */
# ifdef __USE_GNU
char domainname[_UTSNAME_DOMAIN_LENGTH]; //當前網域名稱
# else
char __domainname[_UTSNAME_DOMAIN_LENGTH];
# endif
#endif
};
返回說明:
成功執行時,返回0。失敗返回-1,errno被設為EFAULT,表示buf無效。
關於uname的具體用法可以使用“man uname”來查看。
執行個體如下:
#include <sys/utsname.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
struct utsname testbuff;
int fb=0;
fb=uname(&testbuff);
if(fb<0)
{
perror("uname");
return 0;
}else
{
printf(" sysname:%s/n nodename:%s/n release:%s/n version:%s/n machine:%s/n/n ",/
testbuff.sysname,/
testbuff.nodename,/
testbuff.release,/
testbuff.version,/
testbuff.machine);
#if _UTSNAME_DOMAIN_LENGTH - 0
# ifdef __USE_GNU
printf(" domainame:%s/n ",testbuff.domainname);
//char domainname[_UTSNAME_DOMAIN_LENGTH]; //當前網域名稱
# else
printf(" __domainame:%s/n ",testbuff.__domainname);
//char __domainname[_UTSNAME_DOMAIN_LENGTH];
# endif
#endif
}
return 0;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.