@@ -31,6 +31,7 @@ import (
3131 "golang.org/x/sys/unix"
3232
3333 "github.com/containerd/console"
34+ "github.com/containerd/containerd/errdefs"
3435 "github.com/containerd/containerd/runtime/proc"
3536 "github.com/containerd/fifo"
3637 runc "github.com/containerd/go-runc"
@@ -49,7 +50,7 @@ type execProcess struct {
4950 io runc.IO
5051 status int
5152 exited time.Time
52- pid * safePid
53+ pid safePid
5354 closers []io.Closer
5455 stdin io.Closer
5556 stdio proc.Stdio
@@ -95,6 +96,7 @@ func (e *execProcess) setExited(status int) {
9596 e .status = status
9697 e .exited = time .Now ()
9798 e .parent .Platform .ShutdownConsole (context .Background (), e .console )
99+ e .pid .set (StoppedPID )
98100 close (e .waitBlock )
99101}
100102
@@ -142,7 +144,12 @@ func (e *execProcess) Kill(ctx context.Context, sig uint32, _ bool) error {
142144
143145func (e * execProcess ) kill (ctx context.Context , sig uint32 , _ bool ) error {
144146 pid := e .pid .get ()
145- if pid != 0 {
147+ switch {
148+ case pid == 0 :
149+ return errors .Wrap (errdefs .ErrFailedPrecondition , "process not created" )
150+ case pid < 0 :
151+ return errors .Wrapf (errdefs .ErrNotFound , "process already finished" )
152+ default :
146153 if err := unix .Kill (pid , syscall .Signal (sig )); err != nil {
147154 return errors .Wrapf (checkKillError (err ), "exec kill error" )
148155 }
@@ -248,10 +255,13 @@ func (e *execProcess) Status(ctx context.Context) (string, error) {
248255 }
249256 e .mu .Lock ()
250257 defer e .mu .Unlock ()
251- // if we don't have a pid then the exec process has just been created
258+ // if we don't have a pid(pid=0) then the exec process has just been created
252259 if e .pid .get () == 0 {
253260 return "created" , nil
254261 }
262+ if e .pid .get () == StoppedPID {
263+ return "stopped" , nil
264+ }
255265 // if we have a pid and it can be signaled, the process is running
256266 if err := unix .Kill (e .pid .get (), 0 ); err == nil {
257267 return "running" , nil
0 commit comments