Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with script to kill process

Status
Not open for further replies.

lpblauen

Technical User
Dec 2, 2004
193
US
Since I have a menu program that waits for time to pass with no input I need to kill processes it creates when it does its thing. I will try to explain.
When I run the menu program it puts a sleep in the procces list. I have a pid and a ppid. That tells me the current sleep. If I hit enter or do a menu function when it returns to the main menu program I get a new pid and the old pid and ppid change. I want to go and kill the old pid if the ppid goes to 1. How can I do this?

Example here I'm running the menu program.
systrain2 :/ >ps -ef | grep sleep | awk '{print $2,$3}'
18878 18090
As you can see it has a good pid and ppid
If I hit enter or go to a menu function and come back I get a new pid ppid and the old pid ppid changes to 1
systrain2 :/ >ps -ef | grep sleep | awk '{print $2,$3}'
12066 13104
16704 1
18098 1
18878 1

This will build till the timeout happens. How can I based on this info do a kill on all sleep ppid's that go to 1 that way only the new one is active. I have manually killed the ones with ppid of 1 and the menu still works.

Thanks for any ideas...
 
I figured it out. I just need to add this to my menu program. See below

ps -ef | grep sleep | awk '{print $2,$3}' >1
cat 1 | while read A B
do
if [ "$B" = "1" ]; then
kill -9 $A 2>&1
echo $A
else
print " "
fi
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top