Wait waits for the process to exit and cleans up resources in the end.
()
| 214 | |
| 215 | // Wait waits for the process to exit and cleans up resources in the end. |
| 216 | func (p *Process) Wait() error { |
| 217 | for { |
| 218 | // We use a poll on the pidfd because the usual wait4(2) way doesn't let us |
| 219 | // wait on non-children processes (see https://stackoverflow.com/a/1157739). |
| 220 | exited, err := p.poll() |
| 221 | if err != nil { |
| 222 | if errors.Is(err, unix.EBADF) { |
| 223 | select { |
| 224 | case <-p.Exited: |
| 225 | return nil |
| 226 | default: |
| 227 | } |
| 228 | } |
| 229 | return fmt.Errorf("poll: %w", err) |
| 230 | } |
| 231 | if exited { |
| 232 | break |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | if p.markAsExited() { |
| 237 | // If a process exits with exit(2) or exit_group(2), handleExit is |
| 238 | // responsible for the cleanup. We call cleanup only for processes that |
| 239 | // do not exit cleanly (ex: SIGTERM, SIGKILL). |
| 240 | go p.cleanup() |
| 241 | } |
| 242 | return nil |
| 243 | } |
| 244 | |
| 245 | // markAsExited marks the process as exited. If the process has already been |
| 246 | // marked as exited by someone else, it returns false, otherwise true. |
nothing calls this directly
no test coverage detected