| NEWPID(1) | NEWPID(1) |
NAME¶
newpid - launch a command in a new PID namespace
SYNOPSIS¶
newpid [-inNus] command
DESCRIPTION¶
newpid uses the clone(CLONE_NEWPID) syscall to launch a command in a new PID namespace. The /proc filesystem is remounted so the new process IDs are also visible there.
The command is always started in its own process group, so background processes it starts cannot signal the caller's process group with kill(0, ...), protecting the invoking shell, a test harness, or other jobs on the same host from being taken down by a stray process inside the sandbox.
On top of that, newpid distinguishes two cases automatically. If none of the standard streams is a terminal - a pipeline, cron, an ssh call without a pty, or a test harness such as autopkgtest - a completely new session is started with setsid(2): the command gets its own session and process group and no controlling terminal, so it cannot signal or interact with anything in the caller's session, and is fully decoupled from the invoking shell. This is the strongest isolation newpid provides. If a standard stream is a terminal, the caller's session and controlling terminal are kept so a shell inside behaves normally: the command runs in its own process group and, if it was started as the terminal's foreground process (the normal interactive case), that process group becomes the terminal's foreground group, so interactive shells inside keep full job control; if newpid is started in the background, the terminal is left alone.
Because the command is isolated in its own session and process group, an abort directed at the caller (a process-group kill) can no longer reach it. Therefore newpid installs handlers for SIGHUP, SIGINT, SIGQUIT and SIGTERM and forwards them to the command, so terminating newpid also terminates the sandbox. If newpid is hard-killed (SIGKILL cannot be caught), the command is notified via the parent-death signal instead.
OPTIONS¶
- -i
- Use CLONE_NEWIPC to run in a new IPC namespace.
- -n
- Use CLONE_NEWNET to run in a new network namespace.
- -N newpidname
- Use CLONE_NEWNET to run in a new network namespace, and join an existing network namespace. The name must start with newpid and must not contain a slash; it refers to an entry inside /var/run/netns.
- -u
- Use CLONE_NEWUTS to run in a new UTS namespace.
- -s
- Always start a new session and process group with setsid(2), detached from any controlling terminal, even when a terminal is present. Without -s, a new session is only used when none of the standard streams is a terminal; when run interactively the command stays in the caller's session and runs in its own process group. On a terminal, -s means interactive shells inside have no controlling terminal and no job control.
EXAMPLE¶
$ newpid ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
myon 1 0.0 0.0 4080 84 pts/3 S+ 12:15 0:00 newpid ps aux
myon 2 0.0 0.0 19984 1316 pts/3 R+ 12:15 0:00 ps aux
$ ./newpid -n ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
SEE ALSO¶
AUTHOR¶
Christoph Berg <myon@debian.org>
| 2026-10-13 |