setns调用可以用来加入现有进程的namespace
函数原型
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <sched.h>
int setns(int fd, int nstype);
用例
参考https://github.com/chengxiangwang/enoc.git
$make
$sudo ./main run
main: cloned container pid:14918
# 再开一个terminal tab
$sudo ./main exec 14918
$ps
PID TTY TIME CMD
11 pts/4 00:00:00 bash
19 pts/4 00:00:00 ps
$hostname
container_001