- Creating a slice of length numFDs and later appending elements to it
results in a slice whose first numFDs elements are all nil. It is
sufficient to create a slice of zero length since we are appending
elements to it.
- The current allocation will make ret a slice of length 0. What's
needed is a slice of length len(ofs).
darwin will not perform correctly if there are spaces in the actual
arguments, in which case a single argument will be reported as
multple. Some CGO would be needed to get around this I think.
I couldn't find any good documentation on how windows handles
command line arguments with spaces inside the actual arguments, so
this implementation merely just splits on spaces.
Before it was doing a fillFromStatus() call which was much slower
and none of the information was needed, except by the Name() func
which now will call fillFromStatus() if p.name is not set.
This allows for getting more exact information about each argument
especially if there are arguments that have spaces in them.
This was not implemented for darwin or for windows because they
both currently have not way of properly parsing the cmdline string.
Darwin parses the output of 'ps' which is already whitespace
segmented, and windows just has the cmdline string.
This change changes and documents the (previously undocumented) behavior of Used
to "RAM used by programs".
We also remove the undocumented and unused Shared field of that struct.
So with this change in place, the VirtualMemoryStruct contains:
* three human-consumable fields for Total, Used and Available memory
* one human-consumable UsedPercentage field
* a number of kernel specific fields
Before this change we used to exec() various binaries to find out memory
information.
While this worked, it was awfully slow.
And if somebody would want to compute how many percent of available memory all
PIDs on the system uses, that would take almost ten seconds on my laptop with
the previous implementation.
This implementation fares a lot better, and is smaller.