-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ensures that cmd.Wait() is always called, even if there's a panic in the FromReader function or if stdOut.Close() returns an error * close stdout and ensure wait is called when handling binaries * process cleanup improvements * lint
- Loading branch information
1 parent
6d022e7
commit f3630da
Showing
5 changed files
with
91 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package process | ||
|
||
import ( | ||
"os/exec" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
func GetGitProcessList() []string { | ||
var cmd *exec.Cmd | ||
if runtime.GOOS == "darwin" { | ||
cmd = exec.Command("ps", "-eo", "pid,state,command") | ||
} else { | ||
cmd = exec.Command("ps", "-eo", "pid,stat,cmd") | ||
} | ||
|
||
output, err := cmd.Output() | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
lines := strings.Split(string(output), "\n") | ||
var gitProcesses []string | ||
for _, line := range lines { | ||
if strings.Contains(line, "git") { | ||
gitProcesses = append(gitProcesses, line) | ||
} | ||
} | ||
return gitProcesses | ||
} | ||
|
||
func DetectGitZombies(before, after []string) []string { | ||
beforeMap := make(map[string]bool) | ||
for _, process := range before { | ||
beforeMap[process] = true | ||
} | ||
|
||
var zombies []string | ||
for _, process := range after { | ||
if !beforeMap[process] { | ||
fields := strings.Fields(process) | ||
if len(fields) >= 2 && (fields[1] == "Z" || strings.HasPrefix(fields[1], "Z")) { | ||
zombies = append(zombies, process) | ||
} | ||
} | ||
} | ||
return zombies | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters