LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-29-2006, 01:30 PM   #1
as987
LQ Newbie
 
Registered: Jun 2006
Location: Kansas City, MO USA
Distribution: Fedora Core 5
Posts: 11

Rep: Reputation: 0
Running Tasks When Computer Is Idle


I'm looking for a way to run maintenance tasks when my computer is not being used. I don't leave it on 24x7, so the ideal scenario would be for it to wait until the computer has been idle for a certain period of time (e.g. when the screen saver is running) until it runs maintenance tasks.

I've read the man pages for anacron and it seems like a piece of the puzzle - I just need a way to schedule it to run when the computer is idle. After reading the man page on cron, I didn't see any option in there that would help.

I've searched Google linux and Google groups without much luck:
schedule tasks cpu OR computer idle
cron task idle
etc.

Any pointers would be appreciated.
 
Old 07-29-2006, 02:25 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Simply schedule the task to occur whenever at priority 19. It will use idle CPU cycles, and not interfere to any significant degree with active processes. If you don't leave you computer on all the time, you can use the '@reboot' special cron time to run the process some time after the machine is started. For example:

@reboot /bin/sleep 900 ; /bin/nice -n 19 /usr/local/bin/myprogram

The above crontab entry will schedule the execution to begin 15 minutes after the system is booted. See 'man 5 crontab' for additional details.
 
Old 07-29-2006, 02:37 PM   #3
as987
LQ Newbie
 
Registered: Jun 2006
Location: Kansas City, MO USA
Distribution: Fedora Core 5
Posts: 11

Original Poster
Rep: Reputation: 0
In Windows, I found that option to be less than optimal. Even though these maintenance tasks were run at the lowest priority, if they were disk I/O intensive processes, they would tend to block higher priority processes that were also competing for disk I/O time. I'm assuming this is because it's not as easy to schedule disk time as it is CPU time.

I'm not sure if it would also be a problem with Linux or not.
 
Old 07-29-2006, 03:10 PM   #4
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Then you could always schedule the cron job to wait for the first activation of the screensaver:

@reboot /bin/sleep 900 ; while [ `/usr/bin/xscreensaver-command -time | /bin/awk '{print $4}'` != "blanked" ] ; do /bin/sleep 300 ; done ; /bin/nice -n 19 /usr/local/bin/myprogram

The above will be started after the system is booted and

1- Delay 15 minutes
2- Check every 5 minutes to see if the screen saver has activated
3- Run '/usr/local/bin/myprogram' when the screensaver has activated

Of course, if you return to the system after the screensaver has started, you are back to the same issue.
 
Old 07-29-2006, 03:19 PM   #5
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
If you are running a recent kernel, you can also use the ionice command to reduce the I/O priority. For example:

/bin/nice -n 19 /usr/bin/ionice -c3 /usr/bin/yum -y update

This will run a yum update at idle CPU priority and idle I/O priority.
 
Old 07-30-2006, 10:58 AM   #6
as987
LQ Newbie
 
Registered: Jun 2006
Location: Kansas City, MO USA
Distribution: Fedora Core 5
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks for the tips. I'll give them a try.
 
  


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
Need advice to set up computer for a few simple tasks. JackSmith Linux - Newbie 1 12-13-2005 07:14 PM
Computer requires reboot after idle mpn Slackware 1 10-28-2004 07:21 PM
Laptop Running Hot While Idle? Trey2501 Linux - Laptop and Netbook 6 03-17-2004 06:34 AM
HD runs/searches when computer is idle? DougC Fedora 2 03-04-2004 07:01 AM
tunr computer off when idle gregj_be Programming 7 06-04-2003 01:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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