Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduling in Linux: run a task when computer is idle (= no user input)

I'd like to run Folding@home client on my Ubuntu 8.10 box only when it's idle because of the program's heavy RAM consumption.

By "idle" I mean the state when there's no user activity (keyboard, mouse, etc). It's OK for other (probably heavy) processes to run at that time since F@H has the lowest CPU priority. The point is just to improve user experience and to do heavy work when nobody is using the machine.

How to accomplish this?

like image 328
wheleph Avatar asked Mar 07 '09 19:03

wheleph


3 Answers

When the machine in question is a desktop, you could hook a start/stop script into the screensaver so that the process is stopped when the screensaver is inactive and vice versa.

like image 61
Jan Jungnickel Avatar answered Dec 23 '22 04:12

Jan Jungnickel


It's fiddly to arrange for the process to only be present when the system is otherwise idle.

Actually starting the program in those conditions isn't the hard bit. You have to arrange for the program to be cleanly shut down, and figure out how and when to do that.

You have to be able to distinguish between that process's own CPU usage, and that of the other programs that might be running, so that you can tell whether the system is properly "idle".

It's a lot easier for the process to only be scheduled when the system is otherwise idle. Just use the 'nice' command to launch the Folding@Home client.

However that won't solve the problem of insufficient RAM. If you've got swap space enabled, the system should be able to swap out any low priority processes such that they're not consuming and real resources, but beware of a big hit on disk I/O each time your Folding@Home client swaps in and out of RAM.

p.s. RAM is very cheap at the moment...

p.p.s. see this article

like image 30
Alnitak Avatar answered Dec 23 '22 03:12

Alnitak


may be You need to set on idle task lowest priority via nice.

like image 24
vitaly.v.ch Avatar answered Dec 23 '22 02:12

vitaly.v.ch