A process killing script

A process killing script

Post by Ji » Tue, 10 Oct 2000 09:21:53



Can someone look over this script and let me know what they think?
It is written for BSD, and it seems to work for me. Any comments that
people may have about it would be welcome. I just wrote it to try to
to learn a bit and was hoping someone might be able tell me what I
did right and wrong.

Thanks.

Jim

#!/bin/sh
# A little script for BSD that lets you kill procs

# Is is flawed? I dunno, seems to work for me.
# It might be possible to do this without temp files,
# but I do not know how yet.

proc=`ps x`
thecommand=`echo "$proc" | grep -v ps | awk '{print $5}' | sed -e '1d'`
thepid=`echo "$proc" | grep -v ps | awk '{print $1}' | sed -e '1d'`
echo "$thecommand" > ~/commandtemp$$
echo "$thepid" > ~/pidtemp$$

echo ""

number=1

while read line
do
        echo "$number $line"
        number=`expr $number + 1`
done < ~/commandtemp$$

echo ""
echo -n " Which one do you want to kill? "

read answer

rippid=`cat ~/pidtemp$$ | sed -n "${answer}p"`

echo ""
echo "We are killing `cat ~/commandtemp$$ | sed -n \"${answer}p\"` \
who's PID is $rippid."
echo ""

kill $rippid

rm ~/commandtemp$$
rm ~/pidtemp$$

 
 
 

1. killing a shell script is not killing child processes

dispatcher (NOHUP mode)->daemon->shell script (parent
PID)->executables(child PIDs)

When we try to kill shell script (parent PID) with kill-9 command, I
am expecting that all executables (child PIDs) that are running from
shell script should also be killed.

Shell script process is getting killed but not the child processes.

I tried read all the messages patiently but it added up more
confusions.

I found a way to kill all child processes before killing parent shell
script but trying to find a answer for this behaviour.

Any expert responses are welcome.

Cheers,
Srinivas

2. [PATCH 1/3: FBDEV: VGA State Save/Restore module

3. Terminating process/script with kill -9 or kill -15

4. Top 10 posters comp.unix.shell

5. killing a shell script is not killing child processes

6. help about files lock.

7. How can kill all child processes without killing parent process ?

8. admin question

9. A method to kill process that cannot be killed even with `kill -9'.

10. How to kill process which not killed by 'kill' ?

11. How to Kill Process and Its sub-process and its sub-process??

12. How to Kill a process and its sub-process and its sub-process at a time..

13. need script to start and kill a process