File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 6
6
"path/filepath"
7
7
"strconv"
8
8
"strings"
9
+ "syscall"
9
10
10
11
"github.com/lima-vm/lima/pkg/limayaml"
11
12
"github.com/lima-vm/lima/pkg/store/filenames"
@@ -93,7 +94,8 @@ func Inspect(instName string) (*Instance, error) {
93
94
return inst , nil
94
95
}
95
96
96
- // readPIDFile returns 0 if the PID file does not exist
97
+ // readPIDFile returns 0 if the PID file does not exist or the process has already terminated
98
+ // (in which case the PID file will be removed).
97
99
func readPIDFile (path string ) (int , error ) {
98
100
b , err := os .ReadFile (path )
99
101
if err != nil {
@@ -102,5 +104,21 @@ func readPIDFile(path string) (int, error) {
102
104
}
103
105
return 0 , err
104
106
}
105
- return strconv .Atoi (strings .TrimSpace (string (b )))
107
+ pid , err := strconv .Atoi (strings .TrimSpace (string (b )))
108
+ if err != nil {
109
+ return 0 , err
110
+ }
111
+ proc , err := os .FindProcess (pid )
112
+ if err != nil {
113
+ return 0 , err
114
+ }
115
+ err = proc .Signal (syscall .Signal (0 ))
116
+ if err != nil {
117
+ if errors .Is (err , os .ErrProcessDone ) {
118
+ os .Remove (path )
119
+ return 0 , nil
120
+ }
121
+ return 0 , err
122
+ }
123
+ return pid , nil
106
124
}
You can’t perform that action at this time.
0 commit comments