LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-21-2011, 06:22 AM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 431
Blog Entries: 32

Rep: Reputation: 3
how to kill a process after an hour?


Hi, I wonder if I can kill a process after an hour (I am running cron) so it must be done automatic.
I came up with:
Code:
mplayer -dumpstream -dumpfile ...nothing important here ; sleep 3600 ; killall mplayer
should this work? I searhed online the command format is:
Code:
mplayer -dumpstream -dumpfile ...nothing important here & sleep 3600 ; killall mplayer
What is the difference between ; and & and &&? And the sleep is used when the time is short like a few minutes, I wonder if this will be very heavy to run?
Thanks,
Ted
 
Old 11-21-2011, 07:18 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Well, this is not the right way to do since the kill command should be independent from mplayer. The ; simply separates two linux commands on the same line: this means that the system sleeps 3600 seconds after mplayer has finished. The same for the && syntax which means that the command is executed only if the previous command terminates with a exit status equal to 0 (success). Using a single & is slightly different, since in this case the first command runs in background and the subsequent command immediately starts after that.

Regarding your original question, if you're scheduling the mplayer job, you might schedule a killing job one hour later and use
Code:
/usr/bin/pkill -9 mplayer
in the crontab entry. pkill will kill processes based on the command name, not the PID. Maybe this is what you're looking for.
 
1 members found this post helpful.
Old 11-21-2011, 07:55 AM   #3
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 431

Original Poster
Blog Entries: 32

Rep: Reputation: 3
thanks
 
  


Reply



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
how to kill or clean a Uninterruptible slept session leader process from process tabl golden_boy615 Linux - General 1 12-14-2010 10:47 AM
bash `kill`: process 'B' silently dies; but process 'A' = `kill` spews back debris! GrapefruiTgirl Programming 9 06-23-2009 09:42 AM
How to get the PID of the process giving kill signal to a process? hariprd Programming 2 11-27-2008 03:10 AM
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 03:47 AM
cannot kill process (kill -9 does not work) mazer13a Linux - General 1 05-27-2005 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:26 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration