Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Dec 30, 2024
1 parent 6bf2183 commit 8ee8ae0
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions restartable.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,6 @@ func main() {
}
sort.Ints(pids)

services := make(map[string]bool)

if opts.short < 3 {
fmt.Printf("%s\t%s\t%s\t%-20s\t%20s\t%s\n", "PID", "PPID", "UID", "User", "Service", "Command")
}
Expand All @@ -309,24 +307,22 @@ func main() {
go func() {
for _, pid := range pids {
go func(pid int) {
if info, err := getInfo(pid); info != nil && err == nil {
channel[pid] <- info
} else {
if err != nil {
log.Print(err)
}
close(channel[pid])
info, err := getInfo(pid)
if err != nil {
log.Print(err)
}
channel[pid] <- info
}(pid)
}
}()

services := make(map[string]bool)
for _, pid := range pids {
proc := <-channel[pid]
if proc == nil {
continue
}
//close(channel[pid])
close(channel[pid])
if opts.short < 3 {
fmt.Printf("%d\t%s\t%d\t%-20s\t%20s\t%s\n", pid, proc.ppid, proc.uid, getUser(proc.uid), proc.service, proc.command)
} else if proc.service != "-" {
Expand Down

0 comments on commit 8ee8ae0

Please sign in to comment.