How to kill interactive shell and process/jobs running on it? How to kill interactive shell and process/jobs running on it? docker docker

How to kill interactive shell and process/jobs running on it?


You should get the child(ren) processes first, before killing the shell and kill them too

CPIDS=`pgrep -P $shellpid` # gets pids of child processeskill -9 $shellpidfor cpid in $CPIDS ; do kill -9 $cpid ; done

Or alternatively (this isn't as safe, because, if running series of commands in shell, next one may be called between those two kill commands)

pkill -TERM -P $shellpid # sends TERMINATE signal to childrenkill -9 $shellpid