《UNIX環境高階程式設計》筆記 系統標識

2021-06-20 15:30:28 字數 1282 閱讀 8326

分類: 《unix環境高階程式設計》筆記

2013-10-26 17:23

248人閱讀收藏 

舉報posix.1定義了uname函式,它返回與當前主機和作業系統有關的資訊。

[cpp]view plain

copy

#include 

intuname(

struct

utsname *name);  

//如果成功返回非負值,出錯則返回-1.

utsname結構體的定義如下:

[cpp]view plain

copy

struct

utsname  

實踐:

[cpp]view plain

copy

#include 

#include 

intmain(

void

)  printf("%s,%s,%s,%s,%s\n"

,name.sysname,name.nodename,name.release,name.version,name.machine);  

return

0;  

}   執行結果:

linux,yan-vm,3.5.0-17-generic,#28-ubuntu smp tue oct 9 19:32:08 utc 2012,i686

歷史上,bsd派生的系統提供了gethostname函式,它只返回主機名,該名字通常是tcp/ip網路上主機的名字。

[cpp]view plain

copy

#include 

intgethostname(

char

* name, 

intnamelen); 成功返回0,出錯返回-1.  

實踐:

[cpp]view plain

copy

#include 

#include 

intmain(

void

)  name[99] = '\0'

;  printf("%s\n"

,name);  

return

0;  

}   執行結果:

yan@yan-vm:~/apue$ ./a.out

yan-vm 更多

0

《UNIX環境高階程式設計》筆記23 系統標識

posix.1定義了uname函式,它返回與當前主機和作業系統有關的資訊。cpp view plain copy include intuname struct utsname name 如果成功返回非負值,出錯則返回 1.utsname結構體的定義如下 cpp view plain copy st...

《unix環境高階程式設計》筆記2

第四章 檔案和目錄 本章將描述檔案系統特徵和檔案性質 1 stat fstat和lstat函式 原型 include int stat const char restrict pathname,struct stat restrict buf int fstat int filedes,struct...

UNIX環境高階程式設計學習筆記

include include include include int main int argc,char argv err sys can t open s argv 1 while dirp readdir dp null printf s n dirp d name closedir dp ...