pid1: Do signal handling and orphan reaping for Unix PID1 init processes

[ library, mit, program, system ] [ Propose Tags ]

Please see or view Haddocks at

[Skip to Readme]
Versions [faq],,,
Change log
Dependencies base (>=4.6 && <5), directory, pid1, process (>=1.2), unix [details]
License MIT
Copyright 2016 Michael Snoyman
Author Michael Snoyman
Revised Revision 1 made by HerbertValerioRiedel at 2017-07-14T14:08:13Z
Category System
Home page
Source repo head: git clone
Uploaded by MichaelSnoyman at 2017-07-13T15:47:34Z
Distributions Arch:, Debian:, LTSHaskell:, NixOS:, Stackage:
Executables pid1
Downloads 6780 total (44 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2017-07-13 [all 1 reports]




Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees

Readme for pid1-

[back to package description]


Build Status

Do signal handling and orphan reaping for Unix PID1 init processes.

This provides a Haskell library, and an executable based on that library, for initializing signal handlers, spawning and child process, and reaping orphan processes. These are the responsibilities that must be fulfilled by the initial process in a Unix system, and in particular comes up when running Docker containers.

This library/executable will automatically detect if it is run as some process besides PID1 and, if so, use a straightforward exec system call instead.

NOTE This package is decidedly not portable, and will not work on Windows. If you have a use case where you think it makes sense to run on Windows, I'd be interested in hearing about it.

For a discussion on why this is useful, see this repo.


pid1 [-e|--env ENV] [-u|--user USER] [-g|--group GROUP] [-w|--workdir DIR] [-t|--timeout TIMEOUT] COMMAND [ARG1 ARG2 ... ARGN]


  • -e, --env ENV - Override environment variable from given name=value pair. Can be specified multiple times to set multiple environment variables.
  • -u, --user USER - The username the process will setuid before executing COMMAND
  • -g, --group GROUP - The group name the process will setgid before executing COMMAND
  • -w, --workdir DIR - chdir to DIR before executing COMMAND
  • -t, --timeout TIMEOUT - timeout (in seconds) to wait for all child processes to exit

The recommended use case for this executable is to embed it in a Docker image. Assuming you've placed it at /sbin/pid1, the two commonly recommended usages are:

  1. Override the entrypoint, either via ENTRYPOINT in your Dockerfile or --entrypoint on the command line.

    docker run --rm --entrypoint /sbin/pid1 fpco/pid1 ps
  2. Add /sbin/pid1 to the beginning of your command.

    docker run --rm --entrypoint /usr/bin/env fpco/pid1 /sbin/pid1 ps