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;
                 }
        }

}



------------------------------------------------------------------------------
Index, Search & Analyze Logs and other IT data in Real-Time with Splunk 
Collect, index and harness all the fast moving IT data generated by your 
applications, servers and devices whether physical, virtual or in the cloud.
Deliver compliance at lower cost and gain new business insights. 
Free Software Download: http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to