[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

Mahesh,

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)) {
         perror("unshare");
         return 1;
     }

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

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

     return waitpid(pid, NULL, 0);
}

I recommand you read the documentation 
http://lxc.sourceforge.net/doc/sigops/appcr.pdf

Thanks
   -- Daniel






More information about the lxc-devel mailing list