Skip to content

Instantly share code, notes, and snippets.

@thejohnfreeman
Last active August 23, 2023 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejohnfreeman/410b11858081961caaec0928a4bb5a4a to your computer and use it in GitHub Desktop.
Save thejohnfreeman/410b11858081961caaec0928a4bb5a4a to your computer and use it in GitHub Desktop.
sudo kill

I've got the script below. after running this script, my terminal is broken. my input is not echoed to me, though it is read. I can still run commands. output from commands to stdout is broken: newlines are replaced with long sequences of spaces, so all output is on one very long line. I can use the reset command to fix the terminal.

if I change the SIGKILL to SIGTERM, it is fine. I know that SIGKILL doesn't give the program a chance to shutdown gracefully, but what exactly is going on? what important part of the graceful shutdown is missing that ends up breaking the terminal?

if I remove sudo from the kill command, the same breakage happens. if I remove sudo and change the signal to SIGTERM, then the script hangs on the wait command until the first command exits (presumably the SIGTERM was delivered and ignored).

#!/usr/bin/env bash
sudo sleep 3 >/dev/null 2>&1 </dev/null &
pid=$!
ps ${pid}
sleep 0.1
sudo kill -SIGKILL ${pid}
wait ${pid}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment