LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 07:22 AM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 430
Blog Entries: 30

Rep: Reputation: 2
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, 08:18 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
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, 08:55 AM   #3
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 430

Original Poster
Blog Entries: 30

Rep: Reputation: 2
thanks
 
  


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

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

All times are GMT -5. The time now is 12:43 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration