MCPcopy
hub / github.com/containerd/containerd / WithProcessKill

Function WithProcessKill

client/task_opts.go:148–182  ·  view source on GitHub ↗

WithProcessKill will forcefully kill and delete a process

(ctx context.Context, p Process)

Source from the content-addressed store, hash-verified

146
147// WithProcessKill will forcefully kill and delete a process
148func WithProcessKill(ctx context.Context, p Process) error {
149 // Skip killing tasks with PID 0
150 // https://github.com/containerd/containerd/issues/10441
151 if p.Pid() == 0 {
152 return nil
153 }
154
155 ctx, cancel := context.WithCancel(ctx)
156 defer cancel()
157 // ignore errors to wait and kill as we are forcefully killing
158 // the process and don't care about the exit status
159 s, err := p.Wait(ctx)
160 if err != nil {
161 return err
162 }
163 if err := p.Kill(ctx, syscall.SIGKILL, WithKillAll); err != nil {
164 // Kill might still return an IsNotFound error, even if it actually
165 // killed the process.
166 if errdefs.IsNotFound(err) {
167 select {
168 case <-ctx.Done():
169 return ctx.Err()
170 case <-s:
171 return nil
172 }
173 }
174 if errdefs.IsFailedPrecondition(err) {
175 return nil
176 }
177 return err
178 }
179 // wait for the process to fully stop before letting the rest of the deletion complete
180 <-s
181 return nil
182}
183
184// KillInfo contains information on how to process a Kill action
185type KillInfo struct {

Callers

nothing calls this directly

Calls 5

PidMethod · 0.65
WaitMethod · 0.65
KillMethod · 0.65
DoneMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…