This question is similar to my question about how to list namespaces. So in addtition, I'd like to know some information about moving processes from one namespace to other? E.g. I have processes of current session in one namespace and some other processes of lxc container in different namespace, so I want to run (e.g. links) in cgroup of that container (it's easily do with cgexec) and then move it to container's namespace , because I have to run this process in container without executing it exact in it. Can it be done or it's impossible in Linux??


You don't need to run process in some control groups if you already in certain namespace, instead you have to manipulate with namespaces. All new process in new namespace will «inherit» all control groups related to that namespace.

Moving processes between different namespaces can be done with setns() function or you can use nsenter command from util-linux to enter new namespace and then run new tasks in it. All you need is to know PID of process, which already is new namespace, then you can use (in case you want to run links):

# nsenter --PID --target pid_in_ns_you_want_to_enter && links

It's some cheat, because you don't moving processes, you just entered in namespace and running new processes, but with this possibility you can enter in certain NS and then fork in it already running in other NS process.

  • 3
    Is there anything that allows calling setns from bash, and moving a particular process by their ID to a namespace? – CMCDragonkai Aug 25 '15 at 12:08
  • setns seems to be completely useless: "A multithreaded process may not change user namespace with setns()", "A process may not be reassociated with a new mount namespace if it is multithreaded" – Navin Mar 13 '18 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.