diff --git a/README.rst b/README.rst index 311d856..1fd7677 100644 --- a/README.rst +++ b/README.rst @@ -91,6 +91,7 @@ Current Status - memory_info (linux) - memory_info_ex (linux) - Memory_maps() (linux) <- this is a function + - open_files (linux) - not yet @@ -112,7 +113,6 @@ Current Status - cpu_affinity - memory_percent - children - - open_files - connections - is_running diff --git a/process_linux.go b/process_linux.go index 74fb766..6f9a661 100644 --- a/process_linux.go +++ b/process_linux.go @@ -153,7 +153,24 @@ func fillFromfd(pid int32, p *Process) error { } defer d.Close() fnames, err := d.Readdirnames(-1) - p.Num_fds = int32(len(fnames)) + num_fds := len(fnames) + p.Num_fds = int32(num_fds) + + openfiles := make([]Open_filesStat, num_fds) + for _, fd := range fnames{ + fpath := filepath.Join(statPath, fd) + filepath, err := os.Readlink(fpath) + if err != nil { + continue + } + o := Open_filesStat{ + Path: filepath, + Fd: parseUint64(fd), + } + openfiles = append(openfiles, o) + } + + p.Open_files = openfiles return nil }