-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9ee2d0
commit e874198
Showing
2 changed files
with
14 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ "$#" -ne 1 ]]; then | ||
echo "Wrong number of parameters" | ||
if [[ "$#" -lt 1 || "$#" -gt 2 ]]; then | ||
echo "Usage: $0 <NATLAB_ID> [--SEGV]" | ||
exit 1 | ||
fi | ||
|
||
NATLAB_ID=$1 | ||
SIGNAL="-TERM" # default SIGTERM | ||
|
||
# If the second argument is '--SEGV', send SIGSEGV (-11) to create a coredump | ||
if [[ "$2" == "--SEGV" ]]; then | ||
SIGNAL="-SEGV" | ||
fi | ||
|
||
for pid in $(ps -e -o pid=); do | ||
if grep --null-data --text KILL_ID=${NATLAB_ID} /proc/${pid}/environ; then | ||
cmd=$(tr -d '\000' < /proc/${pid}/cmdline || echo "N/A") | ||
echo "$(date) Killing ${pid} ${cmd}" | ||
kill "${pid}" | ||
echo "$(date) Killing ${pid} ${cmd} with signal: $SIGNAL" | ||
kill "${SIGNAL}" "${pid}" | ||
wait "${pid}" 2>/dev/null | ||
exit 0 | ||
fi | ||
done | ||
|
||
echo "The process to kill not found" | ||
echo "The process to kill was not found: $NATLAB_ID" |
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