lixd / mydocker

参考《自己动手写 docker》从零开始实现一个简易的 docker 以及相关教程。Build a simple Docker from scratch along with related tutorials.
https://www.lixueduan.com/categories/docker/
MIT License
319 stars 35 forks source link

关于第十二课 mydocker stop #3

Closed Chen-Litao closed 4 months ago

Chen-Litao commented 4 months ago

请问一下第十二课中 // 2.发送SIGTERM信号 if err = syscall.Kill(pidInt, syscall.SIGTERM); err != nil { log.Errorf("Stop container %s error %v", containerId, err) return } syscall.SIGTERM换成syscall.SIGTERM是否更合适一点呢

Chen-Litao commented 4 months ago

换成syscall.SIGSTOP

lixd commented 4 months ago

是的,kill 有点粗暴了哈哈,我改一下子

lixd commented 4 months ago

看了一下代码,感觉是弄错了,我以为是直接 SIGKILL 呢, 现在用的 SIGTERM 是 ok 的。 几个 signal 的区别:

SIGKILL kills a process and cannot be caught

SIGTERM kills a process but can be caught to do a graceful exit

SIGSTOP suspends the process until you do a SIGCONT

然后 Docker 的描述

docker stop 就是停止容器,不是暂停容器,因此不是用的 SIGSTOP

Chen-Litao commented 4 months ago

好的好的,感谢回复