Skip to content

Instantly share code, notes, and snippets.

@LoganDark
Last active April 1, 2020 03:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LoganDark/b8c74e14c06b77e6f16d4492c5bda928 to your computer and use it in GitHub Desktop.
Save LoganDark/b8c74e14c06b77e6f16d4492c5bda928 to your computer and use it in GitHub Desktop.
A script that tells you how close most of macOS is to becoming unresponsive. I put this in my PATH.
#!/bin/bash
# macOS Mojave build >18A326g has a nasty issue.
#
# Basically, loginwindow likes threads. It's so passionate about threads that
# it will continue to collect threads endlessly. Now, the problem with such a
# process collecting so many threads is that, as the owner of all processes
# running under your account, if the process crashes, say goodbye to most of
# macOS.
#
# Well, this is exactly what happens. loginwindow freezes at 4096 threads and
# causes most of macOS to become unstable or unusable. For example, most of the
# menu items under the apple menu become useless, such as About This Mac or the
# Sleep/Restart/Shut Down options. Some of the function/media keys stop working
# as well, such as the brightness, keyboard backlight, and volume keys.
#
# I also believe the log out option gets disabled too, but I haven't tested it.
# However, if this is indeed the case, this means the only way to log out
# reliably is using this script with the --kill option, which finds and kills
# loginwindow for you.
WHOAMI=`whoami`
LOGINWINDOW_PID=`ps aux | grep loginwindow | egrep '^'"$WHOAMI"'\s+\d+.+CoreServices' -o | egrep '\S+\s+\d+' -o | head -n 1 | egrep '\d+$' -o`
echo 'Your system is '`expr \( \`ps M "$LOGINWINDOW_PID" | wc -l | egrep '\d+$' -o\` \* 100 \) / 4096`'% crashed'
echo 'loginwindow PID: '"$LOGINWINDOW_PID"
if [ "$1" == "--kill" ]; then
echo 'Killing loginwindow'
sudo kill -9 "$LOGINWINDOW_PID"
else
echo 'To log out and fix the issue, pass --kill'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment