implements Process.open_files on linux.

This commit is contained in:
Shirou WAKAYAMA 2014-04-25 17:19:03 +09:00
parent 887f7514a4
commit db655861e3
2 changed files with 19 additions and 2 deletions

View File

@ -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

View File

@ -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
}