-
Notifications
You must be signed in to change notification settings - Fork 1
/
libspector.go
60 lines (45 loc) · 1.73 KB
/
libspector.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
49
50
51
52
53
54
55
56
57
58
59
60
// Package libspector provides query functions for finding installed libraries
// and libraries used by active processes.
//
// This functionality is implemented by running various platform-native
// commands, concurrency safety is not implemented.
package libspector
import "time"
// Package that is managed by the distribution's package manager.
type Package interface {
// Name of the package.
Name() string
// Version of the package installed.
Version() string
}
// Library is a file representing a dynamically linked library or shared object.
type Library interface {
// Path returns the absolute path of the library on the filesystem.
Path() string
// Ctime returns the last ctime of the library on the filesystem.
Ctime() (time.Time, error)
// Outdated returns whether Process was started earlier than the Ctime time of this library.
Outdated(Process) bool
// Distribution package manager's dependency that owns this library.
Package() (Package, error)
}
// Process is a currently-running process.
type Process interface {
// PID returns the process ID.
PID() int
// Started returns the time when the process was started, if it's still running.
Started() (time.Time, error)
// Find libraries used by this process
Libraries() ([]Library, error)
// Command line used to start the process
CommandArgs() (string, error)
CommandName() (string, error)
}
type Query interface {
// AllProcesses returns all the running processes on the system.
AllProcesses() ([]Process, error)
// FindProcess finds all running processes that match the command substring.
FindProcess(command string) ([]Process, error)
// FindLibrary finds all the installed libraries that match the path substring.
FindLibrary(path string) ([]Library, error)
}