Namespaces in operation, part 4: more on PID namespaces
Namespaces in operation, part 4: more on PID namespaces
Posted Feb 14, 2019 9:58 UTC (Thu) by ywchang (guest, #130070)In reply to: Namespaces in operation, part 4: more on PID namespaces by mkerrisk
Parent article: Namespaces in operation, part 4: more on PID namespaces
I get your point that PID namespace is special, that using `setns()` the calling process itself will not join the new namespace, while the children forked will be joining the new namespace.
I raised the question that if we can drop the `-f`, is because if looking at the implementation of `orphan` codes, the orphan process is actually forked out from the `ns_run`, which has called `setns()` before. That means if `ns_run` serve as the parent, fork the orphan, and then exit. Then the orphan process should in theory be in the new namespace.
I did the experiment, drop the `-f` option, and then I found the orphan did show up in the new namespace. Because I use the readlink against the orphan process outside PID namespace, same with PID namespace `init` process.
I mounted the proc to /proc2, and run `ls -d /proc2/[1-9]*`
The results is like
/proc2/1 /proc2/2
And I run this command to explore /proc2/2, `cat /proc2/2/status | egrep '^(Name|PP*id)'`
it shows me this,
Name: orphan
Pid: 2
PPid: 0
At this moment, I'm confused. Why the orphan process is not reaped by `init` process? And why the PPid is becoming 0?
