Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Script to kill processes

Original Message
Name: brian.barnard
Date: August 5, 2004 at 01:48:18 Pacific
Subject: Script to kill processes
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


Report Offensive Message For Removal


Response Number 1
Name: zarkod
Date: August 5, 2004 at 02:18:58 Pacific
Subject: Script to kill processes
Reply: (edit)

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



Report Offensive Follow Up For Removal

Response Number 2
Name: brian.barnard
Date: August 5, 2004 at 02:26:54 Pacific
Subject: Script to kill processes
Reply: (edit)
Thanks for that, got it working!!!

Brian


Report Offensive Follow Up For Removal

Response Number 3
Name: David Perry
Date: August 5, 2004 at 04:54:10 Pacific
Subject: Script to kill processes
Reply: (edit)
#!/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


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Script to kill processes

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




My PC has been hijacked!

Lexmark 2600 Printer Issues

btk1w1 infected start here post

Unwanted message remians on screen

Slow boot time


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC