LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-20-2008, 06:54 PM   #1
bcameron
LQ Newbie
 
Registered: Oct 2008
Posts: 5

Rep: Reputation: 0
using pkill to kill a specific program after a certain time - help


Hi all,

I have a script which uses a program to convert a series of files. One of the features of the program is a continue function so it can span across disjointed files which are synchronous and it works on a 10second timer.

i.e. if it can find a new joined file in 10seconds then the program continues.

So the problem is that it is hard to batch this program up to do lots of files with this continue flag on as when it cant find the next joined file it just hangs forever and needs to be CTRL-C to kill.

So - finally the question.

How can i use pkill to specifically kill this program after a certain time because i know if i set the time to say 20secs then this is when it has finished and needs to be pkilled so the bash sh can continue...?

something like:

someprogram -i someinputfile
pkill someprogram if timer > 20sec

how do i write this in a sh script where i want to run the script but still keep control over a timer so it can kill it if it has hung?

cheers

Baz.
 
Old 11-20-2008, 07:01 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,972
Blog Entries: 11

Rep: Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876
You almost had it :}

someprogram -i someinputfile&
sleep 20
pkill someprogram
 
Old 11-20-2008, 11:20 PM   #3
bcameron
LQ Newbie
 
Registered: Oct 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Oh...

will this work if somprogram doesnt terminate?

i thought it may need some parallel logic or the pkill with a timer before the command for someprogram..? Or the wait command then || pkill

I did some googling and came up with:

------------------------
for t in $timeout $delay
do
while test $t -gt $interval
do
sleep $interval
kill -0 $$ || exit
t=`expr $t - $interval`
done
sleep $t
kill $SIG $$ && kill -0 $$ || exit
SIG=-KILL
done
) 2> /dev/null &

exec "$@"
-------------------------

this looks sort of what i was thinking but i am a linux newbie so it is a little hard to understand what is going on.

How would you write this in a basic bash shell with the reference to just one program?

Baz.
 
Old 12-07-2008, 02:55 PM   #4
ajkain
LQ Newbie
 
Registered: Apr 2007
Posts: 3

Rep: Reputation: 0
Try this:

echo "pkill -KILL -f 'someprogram'" | at now + 20 minutes
someprogram -i someinputfile
echo "after the death of someprogram"

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kill specific Wine program from Command Line Brian114 Linux - Software 4 06-07-2011 04:02 AM
how to kill the process after specific time? samengr Linux - General 5 02-17-2010 11:19 AM
when a process cann't be terminated through kill/skill/pkill/killall... Osirix Linux - Software 9 07-18-2006 11:16 PM
run program automatically at specific time simon_qwl Programming 2 03-20-2005 10:58 AM
Running a program for a specific period of time CaptainHowdy Linux - Software 2 08-22-2004 07:02 PM


All times are GMT -5. The time now is 07:48 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration