参考jattach,会进入目标命名空间
//进入指定文件描述符fd的命名空间
int enter_ns(int pid, const char* type) {
#ifdef __NR_setns
char path[64], selfpath[64];
snprintf(path, sizeof(path), "/proc/%d/ns/%s", pid, type);
snprintf(selfpath, sizeof(selfpath), "/proc/self/ns/%s", type);
fprintf(stdout, "path is %s \n", path); //proc/10647/ns/net
fprintf(stdout, "selfpath is %s\n", selfpath); ///proc/self/ns/net
//获得
struct stat oldns_stat, newns_stat;
if (stat(selfpath, &oldns_stat) == 0 && stat(path, &newns_stat) == 0) {
// Don't try to call setns() if we're in the same namespace already
if (oldns_stat.st_ino != newns_stat.st_ino) {
int newn