Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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??

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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