When using unshare --pid --fork
, the nsenter
command must attach to the child pid not the unshare
pid to get to the right pid namespace.
I can get unshare's pid as follows:
unshare --pid --mount --fork --mount-proc bash &
echo PID: $!
fg
but I need unshare
's child's pid (2914003) to enter the right namespace:
ps wwfuax | grep -A1 unshare
2914002 pts/4 S 0:00 | \_ unshare --pid --mount --fork --mount-proc bash
2914003 pts/4 S+ 0:00 | \_ bash
This works: nsenter -t 2914003
This does not: nsenter -t 2914002
I was hoping for some kind of option like unshare --show-child-pid
but there isn't.
What is a nice reliable way to get unshare's child's pid?
pgrep -P pid-of-parent-process-here
find the right pid (or pids)?pgrep -o -P pid-of-parent-process-here
will give just one: the first (which will be pid 1 inside)