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

Maheswara Reddy C - ERS, HCL Tech maheswarareddyc at hcl.com
Tue Feb 22 09:44:23 UTC 2011


Hi Daniel,

I have to create 10 namespaces(network), in each namespace I have to run two different processes.

Thanks
Mahesh

-----Original Message-----
From: Daniel Lezcano [mailto:daniel.lezcano at free.fr]
Sent: Tuesday, February 22, 2011 2:47 PM
To: Maheswara Reddy C - ERS, HCL Tech
Cc: lxc-devel at lists.sourceforge.net
Subject: Re: [lxc-devel] do pid1 and pid2 run in the same network namespace

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



::DISCLAIMER::
-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in
this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates.
Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
received this email in error please delete it and notify the sender immediately. Before opening any mail and
attachments please check them for viruses and defect.

-----------------------------------------------------------------------------------------------------------------------




More information about the lxc-devel mailing list