Skip to content

Instantly share code, notes, and snippets.

@handstandsam
Created August 17, 2017 20:14
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 handstandsam/9b51db0a96f307f3393b58742c5dffc9 to your computer and use it in GitHub Desktop.
Save handstandsam/9b51db0a96f307f3393b58742c5dffc9 to your computer and use it in GitHub Desktop.
Killing Hung Emulators on CI (Mac & Linux Commands)
15:56:46 Found Emulator -> 1-04:55:18 93339 qemu-system-i38
15:56:46 EMULATOR has been running longer than an hour 1-04:55:18, KILLING PID 93339
15:56:46 Found Emulator -> 1-04:30:54 94320 qemu-system-i38
15:56:46 EMULATOR has been running longer than an hour 1-04:30:54, KILLING PID 94320
15:56:46 Found Emulator -> 1-02:16:26 96137 qemu-system-i38
15:56:48 EMULATOR has been running longer than an hour 1-02:16:26, KILLING PID 96137
15:56:48 Found Emulator -> 23:41:33 100149 qemu-system-i38
15:56:48 EMULATOR has been running longer than an hour 23:41:33, KILLING PID 100149
15:56:48 Found Emulator -> 23:40:02 100494 qemu-system-i38
15:56:48 EMULATOR has been running longer than an hour 23:40:02, KILLING PID 100494
15:56:48 Found Emulator -> 21:39:20 103253 qemu-system-i38
15:56:48 EMULATOR has been running longer than an hour 21:39:20, KILLING PID 103253
15:56:48 Found Emulator -> 01:29:14 110380 qemu-system-i38
15:56:48 EMULATOR has been running longer than an hour 01:29:14, KILLING PID 110380
15:56:48 Found Emulator -> 37:02 111982 qemu-system-i38
15:56:48 EMULATOR is running less than an hour 37:02, leaving it alone.
15:56:48 Found Emulator -> 16:19 112966 qemu-system-i38
15:56:48 EMULATOR is running less than an hour 16:19, leaving it alone.
#!/bin/bash
# Will find all emulator processes that have been running longer than an hour, and kill -9 them.
SEARCH_TERM="qemu-system"
echo "$(ps eaxo etime,pid,comm | grep "${SEARCH_TERM}")" | while read line
do
echo "Found Emulator -> $line"
COLUMNS=()
for word in $line
do
COLUMNS+=($word)
done
TIME=${COLUMNS[0]}
PID=${COLUMNS[1]}
COMM=${COLUMNS[2]}
# --- Time Formatting Notes ---
# Ten Seconds would be 00:10
# Ten Minutes, Ten Seconds would be 10:10
# One Hour, Ten Minutes, Ten Seconds, would be 01:10:10
# Three Days, One Hour, Ten Minutes, Ten Seconds, would be 03-01:10:10
# Kill the process if the length of the time string is greater than five (greater than one hour)
if [ "${#TIME}" -gt 5 ]; then
echo "EMULATOR has been running longer than an hour ${TIME}, KILLING PID ${PID}"
kill -9 ${PID}
else
echo "EMULATOR is running less than an hour ${TIME}, leaving it alone."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment