staticvoidsigreap(int signo){ while (waitpid(-1, NULL, WNOHANG) > 0) ; }
intmain(int argc, char **argv){ int i; for (i = 1; i < argc; ++i) { if (!strcasecmp(argv[i], "-v")) { printf("pause.c %s\n", VERSION_STRING(VERSION)); return0; } }
if (getpid() != 1) /* Not an error because pause sees use outside of infra containers. */ fprintf(stderr, "Warning: pause should be the first process\n");
zerun.dong$ man waitpid WAIT(2) BSD System Calls Manual WAIT(2)
NAME wait, wait3, wait4, waitpid -- wait for process termination
SYNOPSIS #include <sys/wait.h>
在 mac 上查看 man 手册,wait for process termination 也确实这么写的。登到 ubuntu 18.04 查看一下
1 2 3 4 5
:~# man waitpid WAIT(2) Linux Programmer's Manual WAIT(2)
NAME wait, waitpid, waitid - wait for process to change state
对于 linux man 手册,就变成了 wait for process to change state 等待进程的状态变更!!!
1 2 3 4
All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed. A state change is considered to be: the child terminated; the child was stopped by a signal; or the child was resumed by a signal. In the case of a terminated child, performing a wait allows the system to release the resources associated with the child; if a wait is not performed, then the terminated child remains in a "zombie" state (see NOTES below).
~$ kubectl attach -it nginx -c shell If you don't see a command prompt, try pressing enter. / # ps aux PID USER TIME COMMAND 1 root 0:00 /pause 8 root 0:00 nginx: master process nginx -g daemon off; 41 101 0:00 nginx: worker process 42 root 0:00 sh 49 root 0:00 ps aux
~$ kubectl describe pod nginx ...... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SandboxChanged 3m1s (x2 over 155m) kubelet Pod sandbox changed, it will be killed and re-created. Normal Killing 3m1s (x2 over 155m) kubelet Stopping container nginx Normal Killing 3m1s (x2 over 155m) kubelet Stopping container shell Normal Pulling 2m31s (x3 over 156m) kubelet Pulling image "nginx" Normal Pulling 2m28s (x3 over 156m) kubelet Pulling image "busybox" Normal Created 2m28s (x3 over 156m) kubelet Created container nginx Normal Started 2m28s (x3 over 156m) kubelet Started container nginx Normal Pulled 2m28s kubelet Successfully pulled image "nginx" in 2.796081224s Normal Created 2m25s (x3 over 156m) kubelet Created container shell Normal Started 2m25s (x3 over 156m) kubelet Started container shell Normal Pulled 2m25s kubelet Successfully pulled image "busybox" in 2.856292466s
k8s 检测到 pause 容器状态异常,就会重启该 POD, 其实也不难理解,无论是否共享 PID namespace, infra 容器退出了,POD 必然要重启,毕竟生命周期是与 infra 容器一致的。