mitchellh / go-ps

Find, list, and inspect processes from Go (golang).
https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc
MIT License
1.47k stars 251 forks source link

Add solaris support #21

Closed gfrey closed 7 years ago

gfrey commented 7 years ago

As solaris has a /proc this is pretty similar to linux. Restructured the code a little, so that only UnixProcess' Refresh method had to be implemented.

The assumption is that Executable() returns only the name of the binary started. On solaris this is truncated to 16 characters.

mitchellh commented 7 years ago

This looks pretty good, but we'd like to try to not introduce a cgo requirement for any OS on this library. It looks like the code though could probably be structured a lot like the FreeBSD one by recreating the psinfo struct in Go and loading it there. Would you be open to that?

gfrey commented 7 years ago

I tried to do so, but failed. Problem seems to be, that the /proc/<pid>/psinfo file has 336 bytes (reported by ls and when reading with python and c). But whenever I read that file with golang, I get 416 bytes. Pretty clueless at the moment.

gfrey commented 7 years ago

Well, the solution is that whatever I did to evaluate the size of the /proc/<pid>/psinfo file, I did it with 32bit binaries. From man -s4 proc:

The format of the contents of any /proc file depends on the data model of the observer (the controlling process), not on the data model of the target process.

Now without the cgo dependency.

jen20 commented 7 years ago

@mitchellh This LGTM and seems to work correctly on Illumos - merging will help port Nomad to Illumos.

mitchellh commented 7 years ago

@jen20 Sounds good, I just needed a verification + the removal of cgo. Both appear to now exist. :)