1// +build solaris 2 3package ps 4 5import ( 6 "encoding/binary" 7 "fmt" 8 "os" 9) 10 11type ushort_t uint16 12 13type id_t int32 14type pid_t int32 15type uid_t int32 16type gid_t int32 17 18type dev_t uint64 19type size_t uint64 20type uintptr_t uint64 21 22type timestruc_t [16]byte 23 24// This is copy from /usr/include/sys/procfs.h 25type psinfo_t struct { 26 Pr_flag int32 /* process flags (DEPRECATED; do not use) */ 27 Pr_nlwp int32 /* number of active lwps in the process */ 28 Pr_pid pid_t /* unique process id */ 29 Pr_ppid pid_t /* process id of parent */ 30 Pr_pgid pid_t /* pid of process group leader */ 31 Pr_sid pid_t /* session id */ 32 Pr_uid uid_t /* real user id */ 33 Pr_euid uid_t /* effective user id */ 34 Pr_gid gid_t /* real group id */ 35 Pr_egid gid_t /* effective group id */ 36 Pr_addr uintptr_t /* address of process */ 37 Pr_size size_t /* size of process image in Kbytes */ 38 Pr_rssize size_t /* resident set size in Kbytes */ 39 Pr_pad1 size_t 40 Pr_ttydev dev_t /* controlling tty device (or PRNODEV) */ 41 42 // Guess this following 2 ushort_t values require a padding to properly 43 // align to the 64bit mark. 44 Pr_pctcpu ushort_t /* % of recent cpu time used by all lwps */ 45 Pr_pctmem ushort_t /* % of system memory used by process */ 46 Pr_pad64bit [4]byte 47 48 Pr_start timestruc_t /* process start time, from the epoch */ 49 Pr_time timestruc_t /* usr+sys cpu time for this process */ 50 Pr_ctime timestruc_t /* usr+sys cpu time for reaped children */ 51 Pr_fname [16]byte /* name of execed file */ 52 Pr_psargs [80]byte /* initial characters of arg list */ 53 Pr_wstat int32 /* if zombie, the wait() status */ 54 Pr_argc int32 /* initial argument count */ 55 Pr_argv uintptr_t /* address of initial argument vector */ 56 Pr_envp uintptr_t /* address of initial environment vector */ 57 Pr_dmodel [1]byte /* data model of the process */ 58 Pr_pad2 [3]byte 59 Pr_taskid id_t /* task id */ 60 Pr_projid id_t /* project id */ 61 Pr_nzomb int32 /* number of zombie lwps in the process */ 62 Pr_poolid id_t /* pool id */ 63 Pr_zoneid id_t /* zone id */ 64 Pr_contract id_t /* process contract */ 65 Pr_filler int32 /* reserved for future use */ 66 Pr_lwp [128]byte /* information for representative lwp */ 67} 68 69func (p *UnixProcess) Refresh() error { 70 var psinfo psinfo_t 71 72 path := fmt.Sprintf("/proc/%d/psinfo", p.pid) 73 fh, err := os.Open(path) 74 if err != nil { 75 return err 76 } 77 defer fh.Close() 78 79 err = binary.Read(fh, binary.LittleEndian, &psinfo) 80 if err != nil { 81 return err 82 } 83 84 p.ppid = int(psinfo.Pr_ppid) 85 p.binary = toString(psinfo.Pr_fname[:], 16) 86 return nil 87} 88 89func toString(array []byte, len int) string { 90 for i := 0; i < len; i++ { 91 if array[i] == 0 { 92 return string(array[:i]) 93 } 94 } 95 return string(array[:]) 96} 97