2016微軟認證考試uptime命令的用法

uptime命令可以顯示系統已經運行了多長時間,信息顯示依次爲:現在時間、系統已經運行了多長時間、目前有多少登陸用戶、系統在過去的1分鐘、5分鐘和15分鐘內的平均負載。

2016微軟認證考試uptime命令的用法

uptime命令用法十分簡單:直接輸入uptime即可.

另外還有一個參數 -V ,是用來查詢版本的。 (注意是大寫的字母v)

[linux @ localhost]$ uptime –V

procps version 3.2.7

[linux @ localhost]$ uptime

顯示結果爲:

10:19:04 up 257 days, 18:56, 12 users, load average: 2.10, 2.10,2.09

顯示內容說明:

10:19:04 //系統當前時間

up 257 days, 18:56 //主機已運行時間,時間越大,說明你的機器越穩定。

12 user //用戶連接數,是總連接數而不是用戶數

load average // 系統平均負載,統計最近1,5,15分鐘的'系統平均負載

那麼什麼是系統平均負載呢? 系統平均負載是指在特定時間間隔內運行隊列中的平均進程數。如果每個CPU內核的當前活動進程數不大於3的話,那麼系統的性能是良好的。如果每個CPU內核的任務數大於5,那麼這臺機器的性能有嚴重問題。如果你的linux主機是1個雙核CPU的話,當Load Average 爲6的時候說明機器已經被充分使用了。

另外,下面這段代碼給出了怎麼樣計算系統啓動時間的方法:

#include

#include

struct sysinfo s_info;

long uptime;

int d,h,m,s;

int main()

{

if(0==sysinfo(&s_info))

{

uptime=s_me;

d=uptime/(3600*24);

h=(uptime/3600)%24;

m=(uptime%3600)/60;

s=(uptime%3600)%60;

printf("d=%d:h=%d:m=%d:s=%d",d,h,m,s);

return 0;

}

return -1;

}

運行結果:

[xxx@wireless time]$ gcc -o uptime uptime.c

[xxx@wireless time]$ ./uptime

d=19:h=0:m=4:s=52

[xxx@wireless time]$