Hi ,
I have a file like this
parentid process id
45 3456
1 7898
45 7890
1 6789
45 7597
now i need to loop through this and if parentid != 45 , then i ned to kill this process.
How to go through this is a problem.
what i thought is this--
while read line
do
if [ parentid -ne 45 ];
then
kill -9 processid
fi
done
Please help me out in this..
Thanks
vbe
July 15, 2008, 5:20am
2
Rules...
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post or send a private message where your goal is to get an answer more quickly.
pn8830
July 15, 2008, 9:18am
3
Something like this may do (assuming your PIDs are in input_file) :
#!/bin/bash
while read line
do
PARENT=$(echo $line | cut -d ' ' -f1)
PID=$(echo $line | cut -d ' ' -f2)
if [ $PARENT == "45" ]
then
echo "Killing PID: $PID"
kill -9 $PID
fi
done < input_file
PN
read can separate line content into multiple variables already separated by $IFS, so no need to cut the line:
while read parent id; do
[ $parent = 45 ] && kill $id
done < file
pn8830
July 15, 2008, 11:01am
5
2 Danny.Chouinard
Good point! Thanks!!!
PN.