在Linux中,咱們經常會使用到uptime命令去看看系統的運行時間,它與一個文件有關,就是/proc/uptime,下面對其進行詳細介紹。 bash
1 2 3 4 |
master@jay-intel:~$ cat /proc/uptime 6447032.12 48185264.69 master@jay-intel:~$ cat /proc/cpuinfo | grep processor | wc -l 8 |
第一列輸出的是,系統啓動到如今的時間(以秒爲單位),這裏簡記爲num1;
第二列輸出的是,系統空閒的時間(以秒爲單位),這裏簡記爲num2。post
注意,不少不少人都知道第二個是系統空閒的時間,可是可能你不知道是,在SMP系統裏,系統空閒的時間有時會是系統運行時間的幾倍,這是怎麼回事呢?
由於系統空閒時間的計算,是把SMP算進去的,就是所你有幾個邏輯的CPU(包括超線程)。ui
系統的空閒率(%) = num2/(num1*N) 其中N是SMP系統中的CPU個數。spa
從上面個人一臺機器上的數據可知,
本機啓動到如今的時間長度爲:6447032.12 seconds = 74.6 days
空閒率爲:48185264.69/(6447032.12*8)=93.4%線程
系統空閒率越大,說明系統比較閒,能夠加劇一些負載;而系統空閒率很小,則可能考慮升級本機器硬件或者遷移部分負載到其餘機器上。code
Some docs from Redhat:
The first number is the total number of seconds the system has been up. The second number is how much of that time the machine has spent idle, in seconds. (Jay’s comments: Please pay attention to SMP system.)blog