nes-proj/tests/utils.sh
Rehan MALAK 08c28f2513 homogenize the way we kill background processes
kill_bg :
        -takes the PID of the process to kill
        -differentiates the sudo case from the non-sudo case
2018-05-19 20:11:35 +02:00

21 lines
296 B
Bash
Executable File

#!/bin/bash
function echo_run( )
{
echo $@
$@
}
function kill_bg( )
{
PID=$1
CMD=$(ps -p $PID -o cmd=)
SUDO=
TOKILL=$PID
if [[ ${CMD:0:5} == "sudo " ]] ; then
SUDO="sudo "
TOKILL=$(ps --ppid $PID -o pid=)
fi
echo_run ${SUDO}kill -9 $TOKILL
}