Skip to content

Commit c5750cd

Browse files
committed
refactor(nginx): replace os.FindProcess with gopsutil for cross-platform process existence check
1 parent fb1d82f commit c5750cd

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

internal/nginx/nginx.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"strconv"
66
"strings"
77
"sync"
8-
"syscall"
98
"time"
109

1110
"github.com/0xJacky/Nginx-UI/internal/docker"
1211
"github.com/0xJacky/Nginx-UI/settings"
12+
"github.com/shirou/gopsutil/v4/process"
1313
"github.com/uozi-tech/cosy/logger"
1414
)
1515

@@ -141,22 +141,18 @@ func isProcessRunning(pidPath string) bool {
141141
return false
142142
}
143143

144-
// Cross-platform process existence check
145-
process, err := os.FindProcess(pid)
144+
// Use gopsutil for cross-platform process existence check
145+
exists, err := process.PidExists(int32(pid))
146146
if err != nil {
147-
logger.Debugf("isProcessRunning pidPath: %s, err: %v", pidPath, err)
147+
logger.Debugf("isProcessRunning pidPath: %s, PidExists err: %v", pidPath, err)
148148
return false
149149
}
150150

151-
// On Unix systems, FindProcess always succeeds and returns a Process for the given pid,
152-
// regardless of whether the process exists. To test whether the process actually exists,
153-
// see whether p.Signal(syscall.Signal(0)) reports an error.
154-
err = process.Signal(syscall.Signal(0))
155-
if err == nil {
156-
// Process exists and we can signal it
151+
if exists {
157152
logger.Debugf("isProcessRunning pidPath: %s, process exists", pidPath)
158153
return true
159154
}
155+
160156
logger.Debugf("isProcessRunning pidPath: %s, process does not exist", pidPath)
161157
return false
162158
}

0 commit comments

Comments
 (0)