Sample Header Ad - 728x90

How do you get the child pid of `unshare` when using --fork for `nsenter -t <pid>`?

4 votes
1 answer
1354 views
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?
Asked by KJ7LNW (525 rep)
Jul 23, 2022, 04:18 AM
Last activity: Jul 23, 2022, 01:09 PM