3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation. #
8 # This program is distributed in the hope that it will be useful, but #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
11 # General Public License for more details. #
13 # You should have received a copy of the GNU General Public License #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
16 # Written by and Copyright (C) Francois Fleuret #
17 # Contact <francois@fleuret.org> for comments & bug reports #
18 #########################################################################
20 # Kills all xterms which are running bash with no sub-process
26 SHELL_NAME=$(basename ${SHELL})
28 # Loop through the pid of xterms
29 for ppid in $(ps h -C xterm -o pid); do
33 # For each, loop through the child shells
34 for pid in $(ps h --ppid $ppid -o pid,cmd | awk '{ if($2 == "'${SHELL_NAME}'") { print $1 }}'); do
35 # For each, count how many sub-process we do have
36 K=$(ps h --ppid $pid -o pid | wc -l)
40 # If there is only one, kill the xterm
41 if [[ $N == 1 ]]; then
43 NB_KILLED=$((NB_KILLED+1))
45 NB_TOTAL=$((NB_TOTAL+1))
48 echo "Killed ${NB_KILLED} / ${NB_TOTAL} XTerm(s)"