Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor process util #297

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions process/process.go
Original file line number Diff line number Diff line change
@@ -6,18 +6,18 @@ import (
)

// CloseProcesses part
func CloseProcesses(filter func(process *ps.Process) bool, skipPids map[int32]struct{}) {
func CloseProcesses(predicate func(process *ps.Process) bool, skipPids map[int32]struct{}) {
processes, err := ps.Processes()
if err != nil {
return
}

for _, process := range processes {
// skip non-chrome processes
if !IsChromeProcess(process) {
// skip processes that do not satisfy the predicate
if !predicate(process) {
continue
}
// skip chrome processes that were already running
// skip processes that are in the skip list
if _, ok := skipPids[process.Pid]; ok {
continue
}
@@ -26,11 +26,11 @@ func CloseProcesses(filter func(process *ps.Process) bool, skipPids map[int32]st
}

// FindProcesses finds chrome process running on host
func FindProcesses(filter func(process *ps.Process) bool) map[int32]struct{} {
func FindProcesses(predicate func(process *ps.Process) bool) map[int32]struct{} {
processes, _ := ps.Processes()
list := make(map[int32]struct{})
for _, process := range processes {
if filter(process) {
if predicate(process) {
list[process.Pid] = struct{}{}
if ppid, err := process.Ppid(); err == nil {
list[ppid] = struct{}{}