How does a kill Process Work?

Is it true that when a kill is sent to a process, the process to be killed can decide whether to terminate itself or not?

kill sends a signal to the designated processes
man signal
man kill
man 7 signal # or man -s 2 signal

I am trying to create a script that will kill a process. I have a file (proc.txt) which contains the process number but I don't seem to be able to tie the content of the file to the "kill -9" command to kill it.

a small

> cat proc.txt | xargs -l1 kill -9

should do it (and work with several PID lines too if any).
But if this doesn't work you probably have unsufficient permissions to kill the process involved.

Script to kill processes:

#!/bin/ksh
if [ $# -gt 0 ]; then
process_name=$1
ps_count=`ps -ef | grep -v 'grep' | grep -v 'kill' | grep -i -c $process_name`
echo "Process count: $ps_count"
set -A array_name `ps -ef | grep -i $process_name | grep -v 'grep' | grep -v 'kill' | awk '{print $2}' | sort -u`
print "ps -ef | grep -i $process_name | grep -v 'grep' | grep -v 'kill' | awk '{print \$2 \$8}' | sort -u -n"

print "${array_name[*]}"
kill_count=0
while [ $kill_count -lt $ps_count ]
do
kill -9 ${array_name[$kill_count]}
# print "kill -15 ${array_name[$kill_count]}"
((kill_count=kill_count+1))
done
else
print "Usage: $0 process_name"
print ""
fi

Have a Unix Problem
Do you have a UNIX Question?

Books About Unix
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Unix Home: Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.