Code: Select all
#!/bin/sh
i="0"
VAR=($(ps | grep "rxvt" | grep -v "grep" | awk '{print $1}'))
while (( ${VAR[$i]} )) ; do
kill -9 "${VAR[$i]}"
i=$((i+1))
done
Code: Select all
#!/bin/sh
i="0"
VAR=($(ps | grep "rxvt" | grep -v "grep" | awk '{print $1}'))
while (( ${VAR[$i]} )) ; do
kill -9 "${VAR[$i]}"
i=$((i+1))
done
puppyluvr wrote: Hello,
Why are you ending up with open terminals???
Zombies, orphaned child processes???
Code: Select all
killzombies() {
ZOMBIES="`ps -H -A | grep '<defunct>' | sed -e 's/ /|/g' | grep -v '|||' | cut -f 1 -d ' ' | tr '\n' ' '`"
for ONEZOMBIE in $ZOMBIES
do
echo "Killing parentless zombie process $ONEZOMBIE"
kill $ONEZOMBIE
done
}
guess that's a little easier!technosaurus wrote:i usually just do
killall rxvt (or urxvt)
Never heard of it....great idea! Works nicely. Thankshave you considered using mrxvt - you can open 100 tabbed terminals in the same window - much lower on resources that way too ... just sayin'
Code: Select all
pid=$(ps aux | grep "rxvt" | awk '{print $2}')&& kill -9 $pid
I was having fun playing with arrays , but there's simpler ways like killallbig_bass wrote:I call this kill_rxvt and I made it a script on my desktop
I have been using this for a long time
it can be used as a kill by name just by replacing rxvt with some other command
JoeCode: Select all
pid=$(ps aux | grep "rxvt" | awk '{print $2}')&& kill -9 $pid
Code: Select all
pid=$(pidof rxvt) && kill -9 $pid
Code: Select all
get_pids(){
for x in /proc/*/exe ;do
case `readlink $x` in
*${1}*)x=${x#/proc/};x=${x%/exe};echo $x;;
esac
done
}
kill `get_pids epdfview`
Code: Select all
killall(){
for x in /proc/*/exe ;do
case `readlink $x` in
*${1}*)x=${x#/proc/};x=${x%/exe};kill $x;;
esac
done
}
I counted 119 instances of the link being "/bin/bash" *technosaurus wrote:grep is a pita with ps, but did you know all of the pids are actually directories in /proc? If you did then you may already know that you can use readlink to find out the name each pid was invoked by
Code: Select all
get_pids(){ for x in /proc/*/exe ;do case `readlink $x` in *${1}*)x=${x#/proc/};x=${x%/exe};echo $x;; esac done } kill `get_pids epdfview`
Code: Select all
count(){
i="0"
for x in /proc/*/exe ;do
var=$(readlink $x)
var2=$(echo $var | grep ${1})
[ $var2 ] && i=$((i+1))
done
echo "$i"
}
count "/bin/bash"
119
I've had a lot, but not _that_ many ... oh wait yes I did, with mrxvt - seems like if you kill mrxvt it doesn't kill the shells that it spawnsjpeps wrote: I counted 119 instances of the link being "/bin/bash" *
Tabbed instances of the mrxvt terminal get only one process.
*edit: a few minutes later, the number had increased to 134
Loading terminals or scripts quickly adds /bin/bash processes that remain. I've put an icon on my tray that kills them. Running X needs a few of them however, so it's necessary to record /bin/bash processes present right after startup.technosaurus wrote:I've had a lot, but not _that_ many ... oh wait yes I did, with mrxvt - seems like if you kill mrxvt it doesn't kill the shells that it spawnsjpeps wrote: I counted 119 instances of the link being "/bin/bash" *
Tabbed instances of the mrxvt terminal get only one process.
*edit: a few minutes later, the number had increased to 134
Code: Select all
#!/bin/sh
## initilize ps-bash. Create do-not-delete list on Startup
for x in /proc/*/exe ;do
var=$(readlink $x | grep "/bin/bash")
if [ $var ]; then
x=${x#/proc/} ;x=${x%/exe}
echo ${x} >>/tmp/ba
fi
done
Code: Select all
#!/bin/sh
## to count processes from terminal, USAGE: [ -c]
var=$(pidof mrxvt)
if [ "$var" -a "$1 != "-c" ]; then
Xdialog --msgbox "Close terminals" 5 25
exit
fi
touch /tmp/mark
/usr/local/ps-bash/ps-bash.sh $@
Code: Select all
#!/bin/sh
## Save initial bash processes to /tmp/ba
## Kill subsequent bash processes
if [ "$1" == "-h" ]; then
echo 'Usage ps-bash [-i -k]
initialize
kill additional processes
'
exit
fi
export op="$@"
init(){
[ -f /tmp/ba ] && rm /tmp/ba
for x in /proc/*/exe ;do
var=$(readlink $x | grep "/bin/bash")
if [ $var ]; then
x=${x#/proc/} ;x=${x%/exe}
echo ${x} >>/tmp/ba
fi
done
}
count(){
## current process
[ -f /tmp/cur ] && rm /tmp/cur
i="0"
for x in /proc/*/exe ;do
var=$(readlink $x | grep "/bin/bash")
if [ "$var" ]; then
i=$((i+1))
cur=$(find ${x} -newer /tmp/mark)
x=${x#/proc/} ;x=${x%/exe}
[ "$cur" ] && echo ${x} >>/tmp/cur
var2=$(cat /tmp/ba | grep ${x})
# echo "line 46: ${var2}"
[ -f /tmp/cur ] && var3=$(cat /tmp/cur | grep ${x})
# echo "line 48 ${var3}"
if [ ! "$var2" -a ! "$var3" ]; then
# echo "line 50 ${x}"
if [ "$op" == "-k" -a ! "$var2" -a ! "$var3" ]; then
echo "killing ${x}"
kill -9 ${x}
fi
fi
fi
done
#echo "${i} /bin/bash processes"
}
if [ "$1" == "-i" ]; then
init
else
count
count
Xdialog --title "ps-bash" --msgbox "${i} /bin/bash processes" 5 30
fi
It will work if there is only one rxvt process. Otherwise, you're instructing it to interpret your list of PIDs as a single long PID containing embedded spaces (i.e., quite invalid).jpeps wrote:interesting note: "$pid" won't workCode: Select all
pid=$(pidof rxvt) && kill -9 $pid
I guess it's more interesting that it works without quotes, since it's not really an array. ${x[0]} is the whole list either way. Yet you can perform separate actions on elements if unquoted.Shep wrote:It will work if there is only one rxvt process. Otherwise, you're instructing it to interpret your list of PIDs as a single long PID containing embedded spaces (i.e., quite invalid).jpeps wrote:interesting note: "$pid" won't workCode: Select all
pid=$(pidof rxvt) && kill -9 $pid
Code: Select all
pid=$(pidof rxvt)
for x in "$pid"; do
echo "ID ${x}"
done
for x in $pid; do
echo "ID ${x}"
done