TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Kill Me Softly – Kill processes in a reliable manner

58 pointsby alanfranzover 10 years ago

11 comments

rdtscover 10 years ago
If you are the one designing your applications, don&#x27;t rely on SIGTERM and clean shutdowns. Design them so SIGKILL is the default way to stop them such that no data is corrupted and persistent state stays consistent. Then you don&#x27;t have to rely on some rarely executed &quot;recovery&quot; code, or even worse take chances of what might happen if SIGTERM doesn&#x27;t work.<p>Handle SIGTERM only if you get a blackbox-like application (a database that will break if you pull the power plug on it) and so on.
评论 #8760104 未加载
评论 #8759919 未加载
评论 #8759978 未加载
评论 #8759952 未加载
tspiteriover 10 years ago
I know it&#x27;s normally a good idea to avoid code duplication, but in this case I would have copied the function inside kms_functions into both kmsn and kmsp, since this removes the dependency on readlink and also makes it possible to move the executables around without care.
评论 #8758512 未加载
评论 #8758231 未加载
评论 #8758479 未加载
peterwwillisover 10 years ago
Alternative modes of operation that would be useful:<p>* Send SIGUSR1 if TERM doesn&#x27;t work<p>* Send SIGCONT if TERM doesn&#x27;t work<p>* Attempt to reap the process<p>* Attempt to ptrace the process<p>* Give a hint as to why it can&#x27;t be killed (like blocked I&#x2F;O, a zombie, etc)<p>* Kill the process group (dangerous!)
评论 #8758705 未加载
评论 #8758241 未加载
alanfranzoniover 10 years ago
Often I need to kill processes, and wait until they&#x27;re dead. I want to send a SIGTERM first, then a SIGKILL if it fails. And I want this process to be automated. That&#x27;s it.
pepveover 10 years ago
I really want to like this. But SIGKILL is such a special instrument in the administrator&#x27;s toolbox that I don&#x27;t want it automatically sent after a short timeout. Moreover I don&#x27;t think anyone should want that. This tool will hide or allow you to ignore important issues with your system.<p>I do unequivocally like the blocking behaviour though, I might implement that for myself.<p>Edit: so just something like this:<p><pre><code> function killwait() { kill $1 while ps -p $1 &amp;&gt;&#x2F;dev&#x2F;null; do sleep 1 done }</code></pre>
评论 #8760031 未加载
评论 #8759938 未加载
vacriover 10 years ago
So instead of two kill messages, we now have two scripts to run, dependent on name or pid?<p>Just put everything in one script - these scripts are shorter than an init boilerplate section - and use an option to switch. Do process names by default, then perhaps use a -p arg to switch the script into &#x27;pid&#x27; mode. Bash&#x27;s &#x27;getopts&#x27; is pretty easy to implement.<p>As it stands, you currently have to waste mental power to figure out whether you want the &#x27;n&#x27; or &#x27;p&#x27; version anyway, so may as well just make it an arg.
评论 #8759725 未加载
benatkinover 10 years ago
A lot of these bash scripts could be replaced with Go programs. It doesn&#x27;t take much code for a bash script to get ugly.
评论 #8759830 未加载
评论 #8759956 未加载
faragonover 10 years ago
In my opinion, current process handling is braindead, both in POSIX and Windows. That could be &quot;fixed&quot; with an additional unique identifier during the OS uptime, in order to allow other processes track instances, and not just the ones doing the fork.
评论 #8760165 未加载
alanfranzoniover 10 years ago
Thank to everybody for the feedback. Standalone executable scripts that are both OSX and Linux compatible are now available.
_cipher_over 10 years ago
&gt; Those should be available on almost any Linux system, even on minimal installs:<p>&gt; [..]<p>&gt; Bash<p>Maybe I&#x27;m nitpicking here, but why Bash _should_ be available?
dankilmanover 10 years ago
Those should be available on almost any Linux system, even on minimal installs:<p>Linux
评论 #8758655 未加载