@@ -5,11 +5,11 @@ import (
5
5
"strconv"
6
6
"strings"
7
7
"sync"
8
- "syscall"
9
8
"time"
10
9
11
10
"github.com/0xJacky/Nginx-UI/internal/docker"
12
11
"github.com/0xJacky/Nginx-UI/settings"
12
+ "github.com/shirou/gopsutil/v4/process"
13
13
"github.com/uozi-tech/cosy/logger"
14
14
)
15
15
@@ -141,22 +141,18 @@ func isProcessRunning(pidPath string) bool {
141
141
return false
142
142
}
143
143
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 ) )
146
146
if err != nil {
147
- logger .Debugf ("isProcessRunning pidPath: %s, err: %v" , pidPath , err )
147
+ logger .Debugf ("isProcessRunning pidPath: %s, PidExists err: %v" , pidPath , err )
148
148
return false
149
149
}
150
150
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 {
157
152
logger .Debugf ("isProcessRunning pidPath: %s, process exists" , pidPath )
158
153
return true
159
154
}
155
+
160
156
logger .Debugf ("isProcessRunning pidPath: %s, process does not exist" , pidPath )
161
157
return false
162
158
}
0 commit comments