Skip to content

Commit

Permalink
Merge pull request #297 from projectdiscovery/refactor_process_utils
Browse files Browse the repository at this point in the history
refactor process util
  • Loading branch information
Mzack9999 authored Dec 27, 2023
2 parents a943d50 + aebd321 commit 7b39276
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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{}{}
Expand Down

0 comments on commit 7b39276

Please sign in to comment.