Skip to content

Child PID auto-reaping (or equivalent) #45

@vasama

Description

@vasama

I develop a portable C++ I/O library. Among the interfaces I provide are

  1. an API for process creation, and
  2. managed process handles (meaning resources are released in the destructor).

On Windows, and using PID FDs (particularly with recent additions), implementing these interfaces is fairly simple, but one for issue: reaping child PIDs. I offer options for customising process creation, such as wait-on-close which can do the waiting (and reaping) in the destructor, or detached process creation (via double forking). However, in order to provide good defaults requires spawning a hidden thread which uses epoll wait upon and reap any child processes created through my library.

As a library, I also cannot use any global solution such as signal handlers to reap child PIDs, as that would affect all children, even if they are not created using my library. And conversely, someone else installing a signal handler would interfere with the reaping of children created using my library. Neither is it helpful to push the responsibility of reaping onto my users.

Ideally I would like to have a means of specifying, upon process creation, that the PID is automatically reaped, regardless of its parent at the time of exit. For my purposes, requiring the grandparent to explicitly reap the child upon early exit of the parent only seems harmful, but I can imagine others potentially wanting that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions