-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess.go
48 lines (43 loc) · 1.7 KB
/
process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2021 Tobias Klauser. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package ps provides functionality to find, list and inspect operating system
// processes, without using cgo or external binaries.
package ps
import "time"
// Process is the generic interface for common process information.
type Process interface {
// PID returns the process ID for this process.
PID() int
// PPID returns the parent process ID for this process.
PPID() int
// UID returns the numeric user ID for this process. On Windows, it
// always returns -1.
UID() int
// GID returns the numeric group ID for this process. On Windows, it
// always returns -1.
GID() int
// ExecutablePath returns the full path to the executable of this
// process. This information might not be available on all platforms or
// if the executable was removed while the process was still running.
ExecutablePath() string
// ExecutableArgs returns the command line arguments for this process,
// including the executable name. This information might not be
// available on all platforms.
ExecutableArgs() []string
// Command returns the command or executable name running this process.
// On some platforms (e.g. macOS and the BSDs) this name might be
// truncated.
Command() string
// CreationTime returns the creation time for this process.
CreationTime() time.Time
}
// Processes returns all currently running processes.
func Processes() ([]Process, error) {
return processes()
}
// FindProcess returns the process identified by pid or an error if no process
// with that identifier is found.
func FindProcess(pid int) (Process, error) {
return findProcess(pid)
}