1
2
3
4
5 package unix
6
7 import (
8 "syscall"
9 )
10
11
12
13
14 func KernelVersion() (major, minor int) {
15 var uname syscall.Utsname
16 if err := syscall.Uname(&uname); err != nil {
17 return
18 }
19
20 var (
21 values [2]int
22 value, vi int
23 )
24 for _, c := range uname.Release {
25 if '0' <= c && c <= '9' {
26 value = (value * 10) + int(c-'0')
27 } else {
28
29
30 values[vi] = value
31 vi++
32 if vi >= len(values) {
33 break
34 }
35 value = 0
36 }
37 }
38
39 return values[0], values[1]
40 }
41
View as plain text