[lxc-devel] do pid1 and pid2 run in the same network namespace

Daniel Lezcano daniel.lezcano at free.fr
Tue Feb 22 09:16:51 UTC 2011

On 02/22/2011 07:41 AM, Maheswara Reddy C - ERS, HCL Tech wrote:
> Hi All,
> Does this way both pid1 and pid2 run in the same network namespace? Or please suggest any other way


please tell us what you want to do.

If you want to create a new network namespace, it is not mandatory to 
use clone. The following program will create a new network stack and all 
new processes will inherit this network namespace.

#include <sched.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])

     pid_t pid;

     if (unshare(CLONE_NEWNET)) {
         return 1;

     pid = fork();
     if (pid < 0) {
         return 1;

     if (!pid) {
         execl("/bin/bash", "/bin/bash", NULL);

     return waitpid(pid, NULL, 0);

I recommand you read the documentation 

   -- Daniel

More information about the lxc-devel mailing list