implements some Process funcs on freebsd.

This commit is contained in:
WAKAYAMA shirou 2014-05-01 18:06:16 +09:00
parent b6d9d462c2
commit 0ab054c576
3 changed files with 92 additions and 21 deletions

View File

@ -77,21 +77,21 @@ Current Status
- Process class
- pid (linux, freebsd, windows)
- ppid (linux, windows)
- ppid (linux, freebsd, windows)
- name (linux)
- cmdline (linux)
- create_time (linux)
- status (linux)
- nwd (linux)
- cwd (linux)
- exe (linux, freebsd, windows)
- uids (linux)
- gids (linux)
- terminal (linux)
- uids (linux, freebsd)
- gids (linux, freebsd)
- terminal (linux, freebsd)
- nice (linux)
- num_fds (linux)
- num_threads (linux, windows)
- num_threads (linux, freebsd, windows)
- cpu_times (linux)
- memory_info (linux)
- memory_info (linux, freebsd)
- memory_info_ex (linux)
- memory_maps() (linux)
- open_files (linux)

View File

@ -32,11 +32,20 @@ func Pids() ([]int32, error) {
}
func (p *Process) Ppid() (int32, error) {
return 0, errors.New("not implemented yet")
k, err := p.getKProc()
if err != nil {
return 0, err
}
return k.KiPpid, nil
}
func (p *Process) Name() (string, error) {
name := ""
return name, errors.New("not implemented yet")
k, err := p.getKProc()
if err != nil {
return "", err
}
return string(k.KiComm[:]), nil
}
func (p *Process) Exe() (string, error) {
return "", errors.New("not implemented yet")
@ -44,6 +53,9 @@ func (p *Process) Exe() (string, error) {
func (p *Process) Cmdline() (string, error) {
return "", errors.New("not implemented yet")
}
func (p *Process) CreateTime() (int64, error) {
return 0, errors.New("not implemented yet")
}
func (p *Process) Cwd() (string, error) {
return "", errors.New("not implemented yet")
}
@ -51,21 +63,53 @@ func (p *Process) Parent() (*Process, error) {
return p, errors.New("not implemented yet")
}
func (p *Process) Status() (string, error) {
return "", errors.New("not implemented yet")
k, err := p.getKProc()
if err != nil {
return "", err
}
return string(k.KiStat[:]), nil
}
func (p *Process) Username() (string, error) {
return "", errors.New("not implemented yet")
}
func (p *Process) Uids() ([]int32, error) {
var uids []int32
return uids, errors.New("not implemented yet")
k, err := p.getKProc()
if err != nil {
return nil, err
}
uids := make([]int32, 0, 3)
uids = append(uids, int32(k.KiRuid), int32(k.KiUID), int32(k.KiSvuid))
return uids, nil
}
func (p *Process) Gids() ([]int32, error) {
var gids []int32
return gids, errors.New("not implemented yet")
k, err := p.getKProc()
if err != nil {
return nil, err
}
gids := make([]int32, 0, 3)
gids = append(gids, int32(k.KiRgid), int32(k.KiNgroups[0]), int32(k.KiSvuid))
return gids, nil
}
func (p *Process) Terminal() (string, error) {
return "", errors.New("not implemented yet")
k, err := p.getKProc()
if err != nil {
return "", err
}
ttyNr := uint64(k.KiTdev)
termmap, err := getTerminalMap()
if err != nil {
return "", err
}
return termmap[ttyNr], nil
}
func (p *Process) Nice() (int32, error) {
return 0, errors.New("not implemented yet")
@ -87,7 +131,12 @@ func (p *Process) NumFDs() (int32, error) {
return 0, errors.New("not implemented yet")
}
func (p *Process) NumThreads() (int32, error) {
return 0, errors.New("not implemented yet")
k, err := p.getKProc()
if err != nil {
return 0, err
}
return k.KiNumthreads, nil
}
func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
@ -103,7 +152,17 @@ func (p *Process) CPUAffinity() ([]int32, error) {
return nil, errors.New("not implemented yet")
}
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
return nil, errors.New("not implemented yet")
k, err := p.getKProc()
if err != nil {
return nil, err
}
ret := &MemoryInfoStat{
RSS: uint64(k.KiRssize),
VMS: uint64(k.KiSize),
}
return ret, nil
}
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
return nil, errors.New("not implemented yet")
@ -219,8 +278,7 @@ func callSyscall(mib []int32) ([]byte, uint64, error) {
return buf, length, nil
}
func NewProcess(pid int32) (*Process, error) {
p := &Process{Pid: pid}
func (p *Process) getKProc() (*KinfoProc, error) {
mib := []int32{CTL_KERN, KERN_PROC, KERN_PROC_PID, p.Pid}
buf, length, err := callSyscall(mib)
@ -237,6 +295,11 @@ func NewProcess(pid int32) (*Process, error) {
return nil, err
}
copyParams(&k, p)
return &k, nil
}
func NewProcess(pid int32) (*Process, error) {
p := &Process{Pid: pid}
return p, nil
}

View File

@ -70,6 +70,14 @@ func (p *Process) Exe() (string, error) {
func (p *Process) Cmdline() (string, error) {
return p.fillFromCmdline()
}
func (p *Process) CreateTime() (int64, error) {
_, _, _, createTime, _, err := p.fillFromStat()
if err != nil {
return 0, err
}
return createTime, nil
}
func (p *Process) Cwd() (string, error) {
return p.fillFromCwd()
}