LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Running Tasks When Computer Is Idle (https://www.linuxquestions.org/questions/linux-newbie-8/running-tasks-when-computer-is-idle-468917/)

as987 07-29-2006 01:30 PM

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.

macemoneta 07-29-2006 02:25 PM

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.

as987 07-29-2006 02:37 PM

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.

macemoneta 07-29-2006 03:10 PM

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.

macemoneta 07-29-2006 03:19 PM

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.

as987 07-30-2006 10:58 AM

Thanks for the tips. I'll give them a try.


All times are GMT -5. The time now is 11:14 PM.