File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,12 @@ package system
22
33import (
44 "fmt"
5+ "io"
56 "os"
6- "path/filepath"
77 "strconv"
88 "strings"
9+
10+ "github.com/opencontainers/runc/internal/pathrs"
911)
1012
1113// State is the status of a process.
@@ -66,8 +68,16 @@ type Stat_t struct {
6668}
6769
6870// Stat returns a Stat_t instance for the specified process.
69- func Stat (pid int ) (stat Stat_t , err error ) {
70- bytes , err := os .ReadFile (filepath .Join ("/proc" , strconv .Itoa (pid ), "stat" ))
71+ func Stat (pid int ) (Stat_t , error ) {
72+ var stat Stat_t
73+
74+ statFile , err := pathrs .ProcPidOpen (pid , "stat" , os .O_RDONLY )
75+ if err != nil {
76+ return stat , err
77+ }
78+ defer statFile .Close ()
79+
80+ bytes , err := io .ReadAll (statFile )
7181 if err != nil {
7282 return stat , err
7383 }
You can’t perform that action at this time.
0 commit comments