2018-03-05

Get Linux kernel version

練習程式,讀取 /proc/version 並且輸出資料。/proc/version 記錄著 Linux kernel 的版本資訊。

#!/usr/bin/env tclsh

set version [open "/proc/version" r]
while {1} {
    if {[chan gets $version line] > 0} {
        puts $line
    } else {
        if {[chan eof $version]} {
            break;
        } else {
            puts "Something is wrong."
            break;
        }
    }
}

chan close $version

procfs

The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information in a hierarchical file-like structure, providing a more convenient and standardized method for dynamically accessing process data held in the kernel than traditional tracing methods or direct access to kernel memory.

沒有留言: