Docker基础技术:Linux Namespace(上)

复制#define _GNU_SOURCE #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <sched.h> #include <signal.h> #include <unistd.h> /* 定义一个给 clone 用的基础技术栈,栈大小1M */ #define STACK_SIZE (1024 * 1024) static char container_stack[STACK_SIZE]; char* const container_args[] = { "/bin/bash",基础技术 NULL }; int container_main(void* arg) { printf("Container - inside the container!n"); /* 直接执行一个shell,以便我们观察这个进程空间里的基础技术资源是服务器租用否被隔离了 */ execv(container_args[0], container_args); printf("Somethings wrong!n"); return 1; } int main() { printf("Parent - start a container!n"); /* 调用clone函数,其中传出一个函数,基础技术还有一个栈空间的基础技术(为什么传尾指针,免费信息发布网因为栈是基础技术反着的) */ int container_pid = clone(container_main, container_stack+STACK_SIZE, SIGCHLD, NULL); /* 等待子进程结束 */ waitpid(container_pid, NULL, 0); printf("Parent - container stopped!n"); return 0; } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.
本文地址:http://www.bhae.cn/html/000b8999910.html
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。