signal sends a signal to a running process. It returns sentinel errors errProcessNotFound and errProcessNotRunning so callers can distinguish failure modes.
(id string, sig string)
| 270 | // sentinel errors errProcessNotFound and errProcessNotRunning |
| 271 | // so callers can distinguish failure modes. |
| 272 | func (m *manager) signal(id string, sig string) error { |
| 273 | m.mu.Lock() |
| 274 | proc, ok := m.procs[id] |
| 275 | m.mu.Unlock() |
| 276 | |
| 277 | if !ok { |
| 278 | return errProcessNotFound |
| 279 | } |
| 280 | |
| 281 | proc.mu.Lock() |
| 282 | defer proc.mu.Unlock() |
| 283 | |
| 284 | if !proc.running { |
| 285 | return errProcessNotRunning |
| 286 | } |
| 287 | |
| 288 | switch sig { |
| 289 | case "kill": |
| 290 | // Use process group kill to ensure child processes |
| 291 | // (e.g. from shell pipelines) are also killed. |
| 292 | if err := signalProcess(proc.cmd.Process, syscall.SIGKILL); err != nil { |
| 293 | return xerrors.Errorf("kill process: %w", err) |
| 294 | } |
| 295 | case "terminate": |
| 296 | // Use process group signal to ensure child processes |
| 297 | // are also terminated. |
| 298 | if err := signalProcess(proc.cmd.Process, syscall.SIGTERM); err != nil { |
| 299 | return xerrors.Errorf("terminate process: %w", err) |
| 300 | } |
| 301 | default: |
| 302 | return xerrors.Errorf("unsupported signal %q", sig) |
| 303 | } |
| 304 | |
| 305 | return nil |
| 306 | } |
| 307 | |
| 308 | // Close kills all running processes and prevents new ones from |
| 309 | // starting. It cancels each process's context, which causes |
no test coverage detected