<p>i'm using the approach described here:</p>
<p><a href="https://medium.com/@felixge/killing-a-child-process-and-all-of-its-children-in-go-54079af94773" rel="nofollow">https://medium.com/@felixge/killing-a-child-process-and-all-of-its-children-in-go-54079af94773</a></p>
<p>to kill a process and all of its children. i've been watching it in action and i've noticed that after issuing the syscall.Kill call, the process and child processes linger for up to 30 seconds before disappearing. has anyone else seen this behavior?</p>
<hr/>**评论:**<br/><br/>aboukirev: <pre><p>If the processes perform IO or wait on sync primitive at the time, the kernel may not be able to kill them immediately. Other than that, don't know what could be happening.</p></pre>cootercodes: <pre><p>good point, it is doing IO. that's probably it</p></pre>neopointer: <pre><p>Try to kill the same process with kill command and see how it behaves</p></pre>goomba_gibbon: <pre><p>Good idea. I'd be very surprised if this was an issue with Go as it should send the signal immediately.</p></pre>Loves_Portishead: <pre><p>Signals are queued by the kernel and delivered when possible. -9 is an exception to this rule which immediately removes the process from the kernel scheduler.</p>
<p>Check "signal mask and pending signals" here: <a href="http://man7.org/linux/man-pages/man7/signal.7.html" rel="nofollow">http://man7.org/linux/man-pages/man7/signal.7.html</a></p></pre>goomba_gibbon: <pre><p>I'm aware of that. SIGKILL can't be trapped and handled by the application.</p>
<p>It should be immediate but I suppose it's still down to the scheduler ultimately. Using kill -9 should be equivalent to sending a SIGKILL from Go.</p></pre>Loves_Portishead: <pre><p>Sure, I just wanted to mention that SIGKILL is a special case, but <em>normally</em> signals are queued and delivered "as soon as the application can receive one" which is subject to the rules laid out in the man page I linked.</p>
<p>Sorry if my post wasn't helpful, a RTFM rarely is, but in this case, it's just unexpected that delivering signals can take a while.</p>
<p>I think also we've all seen that ourselves, frantically hitting a ctrl-c to try and stop a terminal program spooling out the contents of the entire internet (or a binary file :-(!) to the terminal, but it refuses to react. The reasons are similar (although can also have to do with a poorly implemented terminal emulator in that case!)</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传