-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.go
More file actions
72 lines (61 loc) · 1.49 KB
/
Copy pathprocess.go
File metadata and controls
72 lines (61 loc) · 1.49 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
package main
import "strings"
// Process holds all information about a single process.
type Process struct {
PID int
PPID int
ElapsedSec int
Age string
Parsed string
Ports []string
Cwd string
CwdDisplay string
Cmd string
// Tree mode fields
TreePrefix string
TreeDepth int
ParentName string
}
// isUserProcess returns true if this is a process the user would care about.
// homeDir should be the expanded home directory path (e.g. "/Users/armen").
func isUserProcess(p *Process, myPID int, showGUI bool, homeDir string) bool {
cwd := p.Cwd
cmd := p.Cmd
// Always filter self
if p.PID == myPID {
return false
}
// GUI apps mode — include apps even with cwd=/
if showGUI && cwd == "/" {
if strings.Contains(cmd, "/Applications/") || strings.Contains(cmd, "/System/Applications/") {
return true
}
}
if cwd == "?" || cwd == "/" {
return false
}
// Filter system junk (macOS + Linux paths; non-matching ones are harmless)
junkPaths := []string{
// macOS
"/Library/Containers/",
"/private/var/folders/",
"/System/",
"/Applications/",
// Linux
"/snap/",
"/usr/lib/systemd/",
}
for _, junk := range junkPaths {
if strings.Contains(cwd, junk) && !strings.HasPrefix(cwd, homeDir) {
return false
}
}
// Filter sandboxed system services
if strings.Contains(cwd, "/Library/Containers/com.apple.") {
return false
}
if strings.Contains(cwd, "/Library/Containers/net.whatsapp.") {
return false
}
return true
}