hello
I need a shell script that takes the process name as an argument and kills the process.
the process name is avilable in the long listing of the process.../usr/ucb/ps.
this is urgent...pls. help
hello
I need a shell script that takes the process name as an argument and kills the process.
the process name is avilable in the long listing of the process.../usr/ucb/ps.
this is urgent...pls. help
I dont think to kill a process you need a script.
This can be done using kill command.
try man pkill
pgrep, pkill - find or signal processes by name and other
attributes
HTH
something like this u can try
[b]```text
for i in -- get the process name as specific to ur requirement
do
kill ps -ef | grep "$i" | awk 'NR!=1 '{ print $2}'
done
[code]
#!/bin/ksh
for i in `/usr/ucb/ps -wwaux | grep $1 | grep -v grep |awk '{print $2}'`
do
echo $i
#kill -9 $i
done
When I run this I get two different PIDs, one for 116694 and 17002. this happens when i run the command as
$/usr/ucb/ps -wwwaux | grep myServices-Primary
tradmin 16694 0.0 1.4443536220216 ? S 12:41:05 2:18 /opt/barc/bin/engine --pid --run /opt/barc/domain/SOAMP_NTA_DEV//myServices-Primary/myServices-Primary.xyc --innerProcess
$./mytest myservice-primary
I couldnt still manage to still kill the process...as I only wnat to kill this process.
You are picking up the parameter in the command line to the shell script "mytest".
It is rarely necessary to issue "kill -9", depends on your application.
If we use a "while" instead of "for", the script will be more robust if there are no matches.
Untested.
#!/bin/ksh
/usr/ucb/ps -wwaux | grep "$1" | grep -v "grep" | grep -v "mytest" |awk '{print $2}' | while read i
do
echo "$i"
#kill -9 "$i"
done
Is there a way to spot on the process that is only running and list its PID with out printing the current shell's PID ?
In my case I use:
kill -9 `ps -ef |grep 'argument/unique/in/the/process/Iwanna/kill' |grep -v 'grep' |awk '{print$2}'`
Where first it gets the process (grep 'blablabla'), then it filter this process from the grep process you started (grep -v 'grep'), then it gets you only the PID field (awk '{print$2}') and finally kills this process.
You can do it with a script also, for example:
#!/bin/bash
terminate=`ps -ef |grep 'argument/unique/in/the/process/Iwanna/kill' |grep -v 'grep' |awk '{print$2}'`
kill -9 $terminate
#And in case you wanna restard this same process:
argument/unique/in/the/process/Iwanna/kill &
Hope I was of help.