diff options
author | Aaron Ball <nullspoon@oper.io> | 2020-12-30 08:57:54 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2020-12-30 08:57:54 -0700 |
commit | d6522988d5c8d1bbc4c98d4d0d0f2f26dffd867f (patch) | |
tree | 07b4490cdb475bcf85715b6f13581ffd727abd22 | |
parent | 0ce7d31d0ea66cd611c2f490805a3d2a9d1cce7c (diff) | |
download | oper.io-d6522988d5c8d1bbc4c98d4d0d0f2f26dffd867f.tar.gz oper.io-d6522988d5c8d1bbc4c98d4d0d0f2f26dffd867f.tar.xz |
bash waitpid function: Simplify calling code
-rw-r--r-- | posts/bash:waitpid_function.rst | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/posts/bash:waitpid_function.rst b/posts/bash:waitpid_function.rst index a88f515..e08fbfe 100644 --- a/posts/bash:waitpid_function.rst +++ b/posts/bash:waitpid_function.rst @@ -148,13 +148,9 @@ this... # Send SIGTERM kill -15 "${pid}" - # Wait for exit - waitpid "${pid}" "${threshold}" + # Wait for pid exit. If waitpid returned 1, send SIGKILL + waitpid "${pid}" "${threshold}" || kill -9 "${pid}" - # If waitpid returned 1, send a SIGKILL - if [ $? -eq 1 ]; then - kill -9 "${pid}" - fi That code excerpt will wait 12 seconds for the process to exit. If it does not exit within that time, it sends a SIGKILL signal to the process, forcing it to @@ -171,7 +167,7 @@ several greps, trim, cut, and head. This is dangerous for myriad reasons. The better way to do it is to read the process from a pid file that was written at startup (if you're not writing pid files at startup, you should be). This process number is then state checked by looking in the system's proc filesystem -at _/proc/$\{pid}_. This is much safer, and doesn't rely on screenscraping the +at ``/proc/${pid}``. This is much safer, and doesn't rely on screenscraping the output of a tool that has several different 'standard' (eg: gnu, bsd, posix, etc) versions. |