fork
fork + exec
简要翻译一下:
fork
先看一下C里的传统使用方式:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
void child() {
printf("child process\n");
}
int main() {
printf("main process\n");
pid_t pid = fork();
int wstatus;
if (pid == 0) {
child();
} else {
printf("main exit\n");
waitpid(pid, &wstatus, 0);
}
}
运行一下:
$ gcc main.c && ./a.out
main process
main exit
child process
我们看看Docker提供的实现的使用方式:
```golang
package main