Last active
August 18, 2017 07:37
-
-
Save handstandsam/62854d35a1ce407646e77e5851762324 to your computer and use it in GitHub Desktop.
Kill Hung Emulators on CI (Mac & Linux) that have been running more than 1 hour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
if [ "${#line}" -gt 0 ]; then | |
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 | |
else | |
echo "No Emulators Running." | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment