| 1 | //go:build linux |
| 2 | |
| 3 | package runnercfg |
| 4 | |
| 5 | import ( |
| 6 | "bufio" |
| 7 | "os" |
| 8 | "strconv" |
| 9 | "strings" |
| 10 | ) |
| 11 | |
| 12 | // detectMemory leest MemTotal uit /proc/meminfo, in MiB. |
| 13 | func detectMemory() int { |
| 14 | f, err := os.Open("/proc/meminfo") |
| 15 | if err != nil { |
| 16 | return 0 |
| 17 | } |
| 18 | defer f.Close() |
| 19 | sc := bufio.NewScanner(f) |
| 20 | for sc.Scan() { |
| 21 | fields := strings.Fields(sc.Text()) |
| 22 | if len(fields) >= 2 && fields[0] == "MemTotal:" { |
| 23 | kb, _ := strconv.Atoi(fields[1]) |
| 24 | return kb / 1024 |
| 25 | } |
| 26 | } |
| 27 | return 0 |
| 28 | } |