You need to do this using the OS itself. If you are on plan9 or posix, Go will return usage values from the OS for you in the structure returned ProcessState.SysUsage().
cmd := exec.Command("command", "arg1", "arg2")
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
fmt.Println("MaxRSS:", cmd.ProcessState.SysUsage().(*syscall.Rusage).Maxrss)
Note: different platforms may return this in bytes or kilobytes. See more details man getrusage.
source
share