Hi, Once we create 10 network namespaces using unshared(), how could we identify/know the created network namespaces ?
Is based on /proc/pid/ Thanks Mahesh From: Daniel Lezcano [mailto:daniel.lezc...@free.fr] Sent: Tuesday, February 22, 2011 5:26 PM To: Maheswara Reddy C - ERS, HCL Tech Cc: lxc-devel@lists.sourceforge.net Subject: Re: [lxc-devel] do pid1 and pid2 run in the same network namespace On 02/22/2011 12:22 PM, Maheswara Reddy C - ERS, HCL Tech wrote: >> Then it is quite easy. You just have to fork ten times the routine in the >> program I gave you in the previous email. > Hi Daniel, > > But I want to run two different (fork() run same copy) process/threads in > each namespace, that's why I am using clone() which take function pointer of > each process/thered to start. Have fun ;) #include<errno.h> #include<sched.h> #include<stdio.h> #include<unistd.h> #include<stdlib.h> #include<sys/types.h> #include<sys/wait.h> #define NRNS 10 int myroutine1(void) { return 0; } int myroutine2(void) { return 0; } int main(int argc, char *argv[]) { int i; pid_t pid; for (i = 0; i< NRNS; i++) { /* create a new network namespace for my childs */ if (unshare(CLONE_NEWNET)) { perror("unshare"); return 1; } pid = fork(); if (pid< 0) { perror("fork"); return 1; } if (!pid) exit(myroutine1()); pid = fork(); if (pid< 0) { perror("fork2"); return 1; } if (!pid) exit(myroutine2()); } /* create a new netns to not share with the last one * At the end we have 10 netns + 1 this one */ if (unshare(CLONE_NEWNET)) { perror("unshare2"); return 1; } for (;;) { pid = wait(NULL); if (pid< 0) { if (errno == ECHILD) return 0; if (errno == EINTR) continue; perror("wait"); return 1; } } } ::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. ----------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------ What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d _______________________________________________ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel