projects
/
scripts.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d010af7
)
Cosmetics.
author
Francois Fleuret
<francois@fleuret.org>
Fri, 8 Nov 2013 07:11:15 +0000
(08:11 +0100)
committer
Francois Fleuret
<francois@fleuret.org>
Fri, 8 Nov 2013 07:11:15 +0000
(08:11 +0100)
kill-unused-xterms.sh
patch
|
blob
|
history
diff --git
a/kill-unused-xterms.sh
b/kill-unused-xterms.sh
index
21258ba
..
075b2ba
100755
(executable)
--- a/
kill-unused-xterms.sh
+++ b/
kill-unused-xterms.sh
@@
-23,14
+23,21
@@
set -e
NB_KILLED=0
NB_TOTAL=0
NB_KILLED=0
NB_TOTAL=0
-SHELL_NAME=
bash
+SHELL_NAME=
$(basename ${SHELL})
+# Loop through the pid of xterms
for ppid in $(ps h -C xterm -o pid); do
for ppid in $(ps h -C xterm -o pid); do
+
N=0
N=0
+
+ # For each, loop through the child shells
for pid in $(ps h --ppid $ppid -o pid,cmd | awk '{ if($2 == "'${SHELL_NAME}'") { print $1 }}'); do
for pid in $(ps h --ppid $ppid -o pid,cmd | awk '{ if($2 == "'${SHELL_NAME}'") { print $1 }}'); do
+ # For each, count how many sub-process we do have
K=$(ps h --ppid $pid -o pid | wc -l)
N=$((N+K+1))
done
K=$(ps h --ppid $pid -o pid | wc -l)
N=$((N+K+1))
done
+
+ # If there is only one, kill the xterm
if [[ $N == 1 ]]; then
kill -USR2 $ppid
NB_KILLED=$((NB_KILLED+1))
if [[ $N == 1 ]]; then
kill -USR2 $ppid
NB_KILLED=$((NB_KILLED+1))