Util-Linux Archive on lore.kernel.org
 help / color / Atom feed
From: Michael Kerrisk <mtk.manpages@gmail.com>
To: mtk.manpages@gmail.com, Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: [PATCH 8/9] Manual pages: unshare.1: fix examples, part 2
Date: Sat, 23 May 2020 08:43:24 +0200
Message-ID: <20200523064325.78491-8-mtk.manpages@gmail.com> (raw)
In-Reply-To: <20200523064325.78491-1-mtk.manpages@gmail.com>

The explanation of the --kill-child example was quite confused and
also the example shell demo was broken because of quoting issues.

It is not the case that the *children* of 'program' would adopted by
init, but rather that 'program' itself (which would be running as PID
1 inside the namespace and is a child of 'unshare') would be adopted
by init.

Rework the --kill-child example. Add a lot more explanation, and
expand the example shell session to give the reader a much better
picture of what is going on.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
 sys-utils/unshare.1 | 56 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 49 insertions(+), 7 deletions(-)

diff --git a/sys-utils/unshare.1 b/sys-utils/unshare.1
index b8ef371a0..38f7a62cf 100644
--- a/sys-utils/unshare.1
+++ b/sys-utils/unshare.1
@@ -317,16 +317,58 @@ makes sure that the bind mount is created on a shared filesystem.
-Reliable killing of subprocesses of the \fIprogram\fR.
-When \fBunshare\fR gets killed, everything below it gets killed as well.
-Without it, the children of \fIprogram\fR would have orphaned and
-been re-parented to PID 1.
+The following commands demonstrate the use of the
+.B \-\-kill-child
+option when creating a PID namespace, in order to ensure that when
+.B unshare
+is killed, all of the processes within the PID namespace are killed.
+.in +4n
+.BR "# set +m                " "# Don't print job status messages"
+.B # unshare \-\-pid \-\-fork \-\-mount\-proc \-\-kill\-child \-\- \e
+.B "       bash \-\-norc \-c \(aq(sleep 555 &) && (ps a &) && sleep 999\(aq &"
+[1] 53456
+      1 pts/3    S+     0:00 sleep 999
+      3 pts/3    S+     0:00 sleep 555
+      5 pts/3    R+     0:00 ps a
+.BR "# ps h \-o 'comm' $!     " "# Show that background job is unshare(1)"
+.BR "# kill $!               " "# Kill unshare(1)
+.B # pidof sleep
+.B pidof
+command prints no output, because the
+.B sleep
+processes have been killed.
+More precisely, when the
+.B sleep
+process that has PID 1 in the namespace (i.e., the namespace's init process)
+was killed, this caused all other processes in the namespace to be killed.
+By contrast, a similar series of commands where the
+.B \-\-kill\-child
+option is not used shows that when
+.B unshare
+terminates, the processes in the PID namespace are not killed:
 .in +4n
-.B # unshare \-pf \-\-kill-child \-\- bash \-c "(sleep 999 &) && sleep 1000" &
-.B # pid=$!
-.B # kill $pid
+.B # unshare \-\-pid \-\-fork \-\-mount\-proc \-\- \e
+.B "       bash \-\-norc \-c \(aq(sleep 555 &) && (ps a &) && sleep 999\(aq &"
+[1] 53479
+      1 pts/3    S+     0:00 sleep 999
+      3 pts/3    S+     0:00 sleep 555
+      5 pts/3    R+     0:00 ps a
+.B # kill $!
+.B # pidof sleep
+53482 53480

  parent reply index

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-23  6:43 [PATCH 1/9] Manual pages: nsenter.1, unshare.1: update references to *_namespaces(7) pages Michael Kerrisk
2020-05-23  6:43 ` [PATCH 2/9] Manual pages: nsenter.1, unshare.1: add a reference to time_namespaces(7) Michael Kerrisk
2020-05-23  6:43 ` [PATCH 3/9] Manual pages: nsenter.1, unshare.1: remove repeated references to clone(2) Michael Kerrisk
2020-05-23  6:43 ` [PATCH 4/9] Manual pages: unshare.1: improve intro paragraphs Michael Kerrisk
2020-05-23  6:43 ` [PATCH 5/9] Manual pages: nsenter.1: clarify the intro discussion Michael Kerrisk
2020-05-23  6:43 ` [PATCH 6/9] Manual pages: nsenter.1: note that 'file' can be a bind mount Michael Kerrisk
2020-05-23  6:43 ` [PATCH 7/9] Manual pages: unshare.1: fix examples, part 1 Michael Kerrisk
2020-05-23  6:43 ` Michael Kerrisk [this message]
2020-05-23  6:43 ` [PATCH 9/9] Manual pages: unshare.1: fix examples, part 3 Michael Kerrisk
2020-05-25 12:17 ` [PATCH 1/9] Manual pages: nsenter.1, unshare.1: update references to *_namespaces(7) pages Karel Zak
2020-05-25 13:13   ` Michael Kerrisk (man-pages)
2020-05-26  8:50     ` Karel Zak
2020-05-27 12:37       ` Michael Kerrisk (man-pages)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200523064325.78491-8-mtk.manpages@gmail.com \
    --to=mtk.manpages@gmail.com \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Util-Linux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/util-linux/0 util-linux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 util-linux util-linux/ https://lore.kernel.org/util-linux \
	public-inbox-index util-linux

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git