SetOOMScore sets the oom score for the provided pid
(pid, score int)
| 46 | |
| 47 | // SetOOMScore sets the oom score for the provided pid |
| 48 | func SetOOMScore(pid, score int) error { |
| 49 | if score > OOMScoreAdjMax || score < OOMScoreAdjMin { |
| 50 | return fmt.Errorf("value out of range (%d): OOM score must be between %d and %d", score, OOMScoreAdjMin, OOMScoreAdjMax) |
| 51 | } |
| 52 | path := fmt.Sprintf("/proc/%d/oom_score_adj", pid) |
| 53 | f, err := os.OpenFile(path, os.O_WRONLY, 0) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | defer f.Close() |
| 58 | if _, err = f.WriteString(strconv.Itoa(score)); err != nil { |
| 59 | if os.IsPermission(err) && (!runningPrivileged() || userns.RunningInUserNS()) { |
| 60 | return nil |
| 61 | } |
| 62 | return err |
| 63 | } |
| 64 | return nil |
| 65 | } |
| 66 | |
| 67 | // GetOOMScoreAdj gets the oom score for a process. It returns 0 (zero) if either |
| 68 | // no oom score is set, or a sore is set to 0. |
searching dependent graphs…