2018-07-08 mount

Test on VMware machine

unshare(CLONE_NEWNS)
mount /dev/sda1 /mnt/iso*
umount /mnt/iso*

image.png

mount_main.c

#define _GNU_SOURCE
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
#define STACK_SIZE (1024 * 1024)
 
static char child_stack[STACK_SIZE];
char* const child_args[] = {
  "/bin/bash",
  NULL
};

// recursive times in child_main
int num=1;
int times=100000;
//static volatile int cnt=0;

long long get_time() {
    struct timeb t;
    ftime(&t);
    return 1000*t.time + t.millitm;
}

int child_main(void* arg)
{
  int idx = *((int *)arg);
  char c;
  char dst[1024];
  
  long long start = get_time();
  printf("----> [%5d] in child %d\n", getpid(), idx);

  int n;
  for (n=0; n [%5d] child %d out, time: %lld ms\n", getpid(), idx, end2-start);
  return 1;
}
 
int main()
{

    signal(SIGCHLD, SIG_IGN);
    long long start = get_time();
    
    int time;
    pid_t fpid;
    for(time=0; time [%5d] in parent\n", getpid());  
        //waitpid(fpid, NULL, 0);
      }
    }

    printf("----> last fpid %d\n", fpid);   
    //sleep(4);
    wait(NULL);

    long long end = get_time();
    printf("----> [%5d] parent out, time: %lld ms\n", getpid(), end-start); 
    return 0;
}

你可能感兴趣的:(2018-07-08 mount)