Commit Graph

60 Commits (ab66f2d0e1be241d25f2ebe7c2cc1875fdb52270)

Author SHA1 Message Date
Lomanic 76ccf0d220 [process][darwin][freebsd][linux][openbsd] Make process.Children not reliant on pgrep
pgrep -P $PID exits with status of 1 (and nothing in stdout nor stderr) both if
a process doesn't exist or it doesn't have child processes, so we don't
use it anymore on these OSes. We sort PIDs as pgrep did.

Also deprecate the ErrorNoChildren error when there are no child processes,
this is erroneous (simply check for the length of the returned slice, plus
this is not an error per se), this was only returned on linux anyway.

Fixes #1698
Slawek Figiel 977269202e fix: handle invalid KinfoProc size on BSD systems
shirou 5f158096be fix: golangci lint with max -> maxConn
shirou 85f5f3a8e2 process.Uids and process.Gids are now return uint32
Sergey Chernomorets aace5e9d8f Groups in /proc/PID/status has type uint32.
Fix error of parser:
> error get info about worker process status 3150292: strconv.ParseInt:
> parsing "4294967293": value out of range

$ grep Groups /proc/self/status
Groups: 20001 [...] 4294967293
shirou bc060cc227 add SPDX License, remove old build tag, and replace import
Chris Gianelloni a8418dfd73 feat: use lsof for net_connections on FreeBSD
Use net.ConnectionsPidWithContext on FreeBSD, similarly to how it is done
on Darwin. This uses common.CallLsofWithContext underneath the hood, which
will use lsof under the hood, if available.

Tested on FreeBSD 13.2-RELEASE

Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
Lomanic 8b96d2e9e2 [process][posix] Realign process.Name() with python psutil to return same value on python3 scripts processes
e2c79a1 started to blindly set the process name to the full path (instead of the basename) of the cmdline exectuable
if the process name from the process comm was truncated on linux. Python psutil never did that, and this is just wrong
for python (or any executable interpreted script) where the process name is not the interpreter binary but the script
itself.

A new test to check process name value against psutil value is added here, which would hopefully catch any potential
future changes in psutil.

Reverts #542

Fixes #1485
Donal Hurley cf25de7460 Add support for getting process exe in FreeBSD
Ville Skyttä f7e1f36418 refactor: remove unnecessary exec.LookPath calls
Executing the command does the lookup if needed and returns the same
error when not found, no need to do it separately.
Sergey Kozlov 8ae037c8a1 Fix typing issues in createTimeWithContext on Freebsd/i386
Before change:
```
$ GOOS=freebsd GOARCH=386 go build ./process
process\process_freebsd.go:118:26: cannot use k.Start.Sec * 1000 + k.Start.Usec / 1000 (type int32) as type int64 in return argument
```
Ville Skyttä 0306525d78 [process] implement ParentWithContext using PpidWithContext
Removes need for redundant ParentWithContext implementations. It had led
to it being unsupported on FreeBSD and OpenBSD even though
PpidWithContext was available for them, and different implementations
for getting the parent info used in ParentWithContext and
PpidWithContext on Darwin and Linux.
Ville Skyttä 41e2595443 [process][freebsd] implement createTimeWithContext
mmorel-35 1e6b445a8a gofumpt
shirou 0969c9436b delete v2 directory, move v3 to top #1078
Sergey Vinogradov 065e609cbf Refactor "process" package
* All context-less wrapping functions (the ones without WithContext
suffix) were moved into process.go since they all are the same.
* Call context is now passed to all underlying functions in
*WithContext() functions.
* All common *BSD bits were moved to process_bsd.go.
* Process.Tgid() method lacked a WithContext counterpart, so
Process.TgidWithContext() was added for uniformity.
* NewProcessWithContext() function was added since NewProcess() is
used a lot throughout the module, and there is no way to pass a
context to it.

This is a part of #761 effort.
shirou 7e94bb8bcd
Merge pull request #775 from TakayukiBGoto/add_additional_gids_support
[Process] Implement Groups() to get additional gids.
Lomanic 4f0e679e35 [process][darwin][openbsd][freebsd] Fix #795 don't truncate process names to 16 characters
TakayukiB Goto a93796494b [Process] Define the Groups() only once
TakayukiB Goto f55f202e81 [Process] Implement Groups() to get additional gids.
Lomanic 547679f88e [process] Fix #760 implement IsRunning by checking process with same PID has same CreateTime as current process
Lomanic 3eefe64948 [process] Fix #752 sort PIDS returned by process.Pids()
Lomanic 3465186bca [process] Fix #729 check process existence in NewProcess()
Lomanic 41e774419f
Merge pull request #643 from wcc526/master
Update process_linux.go for Add process ConnectionsMax
wcc526 462e0f6c2f Update process_linux.go for Add process ConnectionsMax
David Naylor 414c76f159 [process][linux] Export process page fault info
Add a function for retrieving page fault counts from /proc/[pid]/stat on
Linux.
Lomanic 8ffa453390 #596 Amend last commit, add missing strconv pkg in process_freebsd.go
Lomanic 8ef9b01052 Fix process.Foreground for BSDs, add openbsd implementation
Lomanic 878e0a701b Fix #596 Implement process.Background and process.Foreground functions
shirou 145dca90f7 change to use CommandContext.
shirou 6a368fb7cd [process]: add ProcessesWithContext.
shirou cd61c36c4f
Merge branch 'master' into feature/add_context_support
Nick Kirsch 6c35887d02 Add ErrNotImplementedError to Darwin, FreeBSD, and OpenBSD.
shirou 4c73494c78 Add WithContext functions.
Sam Kleinman 4d92a03da8 fix cross compiles
tycho garen 08a382b207 make process.processes function public
Leonid Podolny 7ee4a4c6ff Fix Threads() signature to better match python original
Leonid Podolny 7ad3836ad3 Implement Threads() for Linux
shirou a452de7c73 Merge pull request #346 from phemmer/rlimit-current
add current values to rlimit retrieval
Sean Chittenden 635b971c0e
Move from the `syscall` package to the `golang.org/x/sys/{unix,windows}`
Patrick Hemmer 60c32eb847 add current values to rlimit retrieval
Shirou WAKAYAMA 613a8a90e1 fixed by golint.
Shirou WAKAYAMA da89408631 Merge branch 'master' into v2
WAKAYAMA shirou 37d8908841 [process]freebsd: implementes proceess.Nice()
WAKAYAMA shirou 37b6b4051f [process]freebsd: process_freebsd_amd64.go is now generated by cgo godefs.
Shirou WAKAYAMA 46ddd57c72 process has NetIOCounters and IOCounters.
Shirou WAKAYAMA ea152ea901 [BREAKING CHANGE] rename functions to pass golint. ex) net.NetIOCounters -> net.IOCounters
Chris Gilling d098bf135f process: fix bug in CmdlineSlice where cmdline is empty
Sometimes (at least on linux) cmdline is empty, this was causing
a panic.
Chris Gilling b8c40ac83c process: add CmdlineSlice function for linux + freebsd
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.
Johan Walles 70444b571b process: Implement platform independent MemoryPercent()
It calls mem.VirtualMemory() and process.MemoryInfo(), so on the platforms where
those work MemoryPercent() will as well.

Tested on Darwin.