Add GetOOMScore function
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
4d313c00ab
commit
c93d645435
@ -20,8 +20,10 @@ package sys
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/opencontainers/runc/libcontainer/system"
|
"github.com/opencontainers/runc/libcontainer/system"
|
||||||
)
|
)
|
||||||
@ -45,3 +47,13 @@ func SetOOMScore(pid, score int) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOOMScoreAdj gets the oom score for a process
|
||||||
|
func GetOOMScoreAdj(pid int) (int, error) {
|
||||||
|
path := fmt.Sprintf("/proc/%d/oom_score_adj", pid)
|
||||||
|
data, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return strconv.Atoi(strings.TrimSpace(string(data)))
|
||||||
|
}
|
||||||
|
@ -20,12 +20,8 @@ package sys
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -85,7 +81,7 @@ func adjustOom(adjustment int) (int, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return readOomScoreAdj(pid)
|
return GetOOMScoreAdj(pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForPid(process *os.Process) (int, error) {
|
func waitForPid(process *os.Process) (int, error) {
|
||||||
@ -106,17 +102,3 @@ func waitForPid(process *os.Process) (int, error) {
|
|||||||
return 0, errors.New("process did not start in 10 seconds")
|
return 0, errors.New("process did not start in 10 seconds")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readOomScoreAdj(pid int) (int, error) {
|
|
||||||
oomScore, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/oom_score_adj", pid))
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
scoreAsInt, err := strconv.Atoi(strings.TrimSpace(string(oomScore)))
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return scoreAsInt, nil
|
|
||||||
}
|
|
||||||
|
@ -22,3 +22,10 @@ package sys
|
|||||||
func SetOOMScore(pid, score int) error {
|
func SetOOMScore(pid, score int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOOMScoreAdj gets the oom score for a process
|
||||||
|
//
|
||||||
|
// Not implemented on Windows
|
||||||
|
func GetOOMScoreAdj(pid int) (int, error) {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user