From c5f25cbc7d6bfd7e198d22a3e8f0a5b06538bca2 Mon Sep 17 00:00:00 2001 From: WindSpiritSR Date: Wed, 8 Jan 2025 12:18:46 +0800 Subject: [PATCH] feat: getPidByPort() supports alpine now (#3483) Signed-off-by: WindSpiritSR --- util/process.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/process.go b/util/process.go index f11eefd8..a0488055 100644 --- a/util/process.go +++ b/util/process.go @@ -29,7 +29,7 @@ func getPidByPort(port int) (int, error) { case "windows": cmd = exec.Command("cmd", "/c", "netstat -ano | findstr :"+strconv.Itoa(port)) case "darwin", "linux": - cmd = exec.Command("lsof", "-i", ":"+strconv.Itoa(port)) + cmd = exec.Command("lsof", "-t", "-i", ":"+strconv.Itoa(port)) default: return 0, fmt.Errorf("unsupported OS: %s", runtime.GOOS) } @@ -59,7 +59,7 @@ func getPidByPort(port int) (int, error) { return pid, nil } } else { - pid, err := strconv.Atoi(fields[1]) + pid, err := strconv.Atoi(fields[0]) if err != nil { return 0, err }