LinuxQuestions.org
Help answer threads with 0 replies.
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 06-11-2004, 03:05 PM   #1
virid
LQ Newbie
 
Registered: Mar 2004
Location: NYC
Distribution: Slackware
Posts: 9

Rep: Reputation: 0
Killing a process after x amount of time...


I want to run a command for 24 hours. After 24 hours I want to kill it. What are some recommended ways of doing this. I'm not looking for a cron job but something that I can do in just one command. Can anyone help??

For example, if I needed to run a process and log it's output for 24 hours but couldn't let it run any longer because the log would fill up all available hard disk space.
 
Old 06-11-2004, 03:08 PM   #2
JJX
Member
 
Registered: Mar 2004
Location: Greece
Distribution: Debian
Posts: 343

Rep: Reputation: 31
You can clean the log after some time (every 24h) [ cp /dev/null log_path ]

cron is exactly what u want If u want to run more than one command create a script , give +x and execute it every 24hrs
 
Old 03-17-2006, 05:25 AM   #3
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
I'm replying just because I had today the same problem and found a different solution nad maybe someone will also stumble on this post. This works for bash shell:

Code:
command &  PID=$! ; sleep 5 ; echo $PID ; kill $PID
The $! expands to the pid of the last command executed in background. Replace sleep 5 with the amount you want.
 
Old 03-17-2006, 06:13 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
If you don't want "sleep" to run for 24 hours, I recommend using "at" to kill the program instead.
Think of "at" like "cron", but executing the command only once (instead of repeatedly).

So, the code is something like (haven't tested it, but should work):
Code:
command &; PID=$!; echo "kill $PID" | at now + 24 hours;
 
  


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
Make most amount of Linux users in least amount of time studpenguin General 24 02-02-2007 03:42 PM
Process killing script owix Linux - General 2 07-19-2005 11:08 AM
Killing a process by its name rabeea Linux - Networking 3 03-17-2005 05:30 AM
killing process at time limit hfawzy Linux - General 0 05-31-2003 03:46 AM
Really Killing a Process! lazlow69 Linux - Newbie 14 05-10-2003 10:31 PM


All times are GMT -5. The time now is 07:44 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