**need help for killing a process through script**

Hello All,

i hope you are fine.
I need a little help from you people--

inside a script i want to kill a parent process by checking it with the child process..

p_pid=`ps -e | awk '/ra_cmd_d/ {print$1}'`

here i am selecting the child process id in p_pid.
next--

sleep_pid=`ps -af | awk '$3 == '${p_pid}' {print $2}'`
 
echo $sleep_pid

here i am cheching the P_PID with the 3rd field of 'ps -af' and selecting the respective 2nd column which is the parent id.

now the problem is when i am echoing sleep_pid its showing two values :confused:.

12545 13345

first one is the valid one but the second value i cant understand y comming. Everytime the 2nd value changed, seems to be randomly generated.

i want sleep_pid to hold only 12545.
can you please help me to get rid of the second value?

many thanks in advance....
Neel....

what is the output of :

ps -e | awk '/ra_cmd_d/ {print $0}'

and from that, what you need.

p_pid=`ps -e | awk '/ra_cmd_d/ {print$1}'`

Is returning only one value 12234 and when i am passing the value in

sleep_pid=`ps -af | awk '$3 == '${p_pid}' {print $2}'`

somehow tho values are comming.
i need the first value.

one note here if i hardcode the value of p_pid then sleep_pid holds only one values as expected.. the problem comes when i try to pass p_pid

sleep_pid=`ps -af | awk '$3 == '${p_pid}' {print $2}'`

Hi,

Try this,

ps -af | awk -v v1=$p_pid '$3 == v1 {print $2}'