Computing.Net > Forums > Unix > Script to kill processes

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Script to kill processes

Reply to Message Icon

Name: brian.barnard
Date: August 5, 2004 at 01:48:18 Pacific
OS: Solaris 8
CPU/Ram: 256
Comment:

Hi,

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.

Any ideas?

Brian



Sponsored Link
Ads by Google

Response Number 1
Name: zarkod
Date: August 5, 2004 at 02:18:58 Pacific
Reply:


Hi Brian,

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.
Bye



0

Response Number 2
Name: brian.barnard
Date: August 5, 2004 at 02:26:54 Pacific
Reply:

Thanks for that, got it working!!!

Brian


0

Response Number 3
Name: David Perry
Date: August 5, 2004 at 04:54:10 Pacific
Reply:

#!/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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Script to kill processes

How to kill processes older than x www.computing.net/answers/unix/how-to-kill-processes-older-than-x-/4238.html

Kill process script www.computing.net/answers/unix/kill-process-script/8017.html

process monitor script (re-post) www.computing.net/answers/unix/process-monitor-script-repost/3910.html