mirror of
https://github.com/deajan/obackup.git
synced 2025-05-10 12:13:41 +02:00
KillChild function works on Linux,bsd,macos
This commit is contained in:
parent
62600fff39
commit
1fa695e3b0
23
obackup.sh
23
obackup.sh
@ -5,7 +5,7 @@
|
|||||||
AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong"
|
AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong"
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||||
PROGRAM_VERSION=1.9pre
|
PROGRAM_VERSION=1.9pre
|
||||||
PROGRAM_BUILD=2015091401
|
PROGRAM_BUILD=2015091501
|
||||||
|
|
||||||
## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode
|
## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode
|
||||||
if ! type -p "$BASH" > /dev/null
|
if ! type -p "$BASH" > /dev/null
|
||||||
@ -110,21 +110,22 @@ function LogDebug
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Highly portable killtree function from http://stackoverflow.com/a/18214698/2635443, modded not to kill itself
|
# Portable child (and grandchild) kill function tester under Linux, BSD and MacOS X, see http://stackoverflow.com/a/32566506/2635443
|
||||||
function KillTree {
|
KillChilds() {
|
||||||
local parent=$1 child
|
local pid="${1}"
|
||||||
|
local self="${2:-false}"
|
||||||
|
|
||||||
for child in $(ps -o ppid= -o pid= | awk "\$1==$parent {print \$2}"); do
|
if children="$(pgrep -P "$pid")"; then
|
||||||
KillTree $child
|
for child in $children; do
|
||||||
|
KillChilds "$child" true
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $parent -ne $$ ]; then
|
if [ "$self" == true ]; then
|
||||||
kill -9 $parent > /dev/null 2>&1
|
kill -s SIGTERM "$pid" || (sleep 10 && kill -9 "$pid" &)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
killtree $$
|
|
||||||
|
|
||||||
function TrapError
|
function TrapError
|
||||||
{
|
{
|
||||||
local JOB="$0"
|
local JOB="$0"
|
||||||
@ -173,7 +174,7 @@ function TrapQuit
|
|||||||
Log "Backup script finshed."
|
Log "Backup script finshed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
KillTree $$
|
KillChilds $$ > /dev/null 2&>1
|
||||||
}
|
}
|
||||||
|
|
||||||
function Spinner
|
function Spinner
|
||||||
|
Loading…
Reference in New Issue
Block a user