$ /bin/nsenter -Z -m -n -p -t 167977 /bin/gstack 1864 #0 0x00007fb66768afb3 in __epoll_wait_nocancel () from /lib64/libc.so.6 #1 0x00007fb667b70f1b in epoll_event_loop_once () from /lib64/libtevent.so.0 #2 0x00007fb667b6f057 in std_event_loop_once () from /lib64/libtevent.so.0 #3 0x00007fb667b6a25d in _tevent_loop_once () from /lib64/libtevent.so.0 #4 0x00007fb667b6a4bb in tevent_common_loop_wait () from /lib64/libtevent.so.0 #5 0x00007fb667b6eff7 in std_event_loop_wait () from /lib64/libtevent.so.0 #6 0x00005588a9175a98 in main ()
We use nsenter to get the stack trace of the target process in contaienr namespace.
$ man nsenter NAME nsenter - run program with namespaces of other processes SYNOPSIS nsenter [options] [program [arguments]] DESCRIPTION Enters the namespaces of one or more other processes and then executes the specified program. Enterable namespaces are: mount namespace Mounting and unmounting filesystems will not affect the rest of the system (CLONE_NEWNS flag), except for filesystems which are explicitly marked as shared (with mount --make-shared; see /proc/self/mountinfo for the shared flag). UTS namespace Setting hostname or domainname will not affect the rest of the system. (CLONE_NEWUTS flag) IPC namespace The process will have an independent namespace for System V message queues, semaphore sets and shared memory segments. (CLONE_NEWIPC flag) network namespace The process will have independent IPv4 and IPv6 stacks, IP routing tables, firewall rules, the /proc/net and /sys/class/net directory trees, sockets, etc. (CLONE_NEWNET flag) PID namespace Children will have a set of PID to process mappings separate from the nsenter process (CLONE_NEWPID flag). nsenter will fork by default if changing the PID namespace, so that the new program and its children share the same PID namespace and are visible to each other. If --no-fork is used, the new pro‐ gram will be exec'ed without forking. user namespace The process will have a distinct set of UIDs, GIDs and capabilities. (CLONE_NEWUSER flag) See clone(2) for the exact semantics of the flags. If program is not given, then ``${SHELL}'' is run (default: /bin/sh).