RunAppWhenIdle -- Run an application when you are not using your computer

Version 2007-11-08
Requirements MS Windows
Development Language C++, MFC
Download runappwhenidle.exe

I wrote RunAppWhenIdle to execute some of the cpu-intensive programs only when I was not using my computer. The cpu-intensive programs were some experiments I was performing as part of my bioinformatics research. I also managed to persuade some of my friends to execute these programs on their computer, and with RunAppWhenIdle, I made sure that their computer usage was not disturbed.

With RunAppWhenIdle, you can either bind to an already running process on your system, or execute a new application. The application will be suspended (not killed!) while you are using your computer, and will resume when you are idle.

Installation

Download and run RunAppWhenIdle from the command prompt. You can specify either a process-id (pid) to bind, or a new program to execute. You can get a list of currently running processes if you run with no command line arguments.

Command-line arguments explained

usage:
RunAppWhenIdle.exe [-idle secs] [-pollIdle milisecs] [-pollUse milisecs] [-cpuLimit 0-100] [-pid procId [-resume] | /path/to/executable argument-list]
Parameter Default Description
-idle 300 (5 mins) Define what idle is; how long of a user inactivity is considered idle
-pollIdle 10000 (10 secs) In what interval should RunAppWhenIdle check for user inactivity
-pollUse 1000 (1 sec) In what interval should RunAppWhenIdle check for user activity
-cpuLimit 20 RunAppWhenIdle does not resume the process if cpu usage is already more than cpuLimit. Set this to 0 if you don't want to consider cpu-usage.
-pid Process id to bind to. Skip this argument if you are specifying the executable to run. Run RunAppWhenIdle with no arguments to get a list of processes currently running on your system.
-resume If -resume is given, RunAppWhenIdle will resume the process with given pid. This is helpful if something went wrong, and your process was kept suspended
/path/to/executable Specify the path to your executable application. This is ignored if you already specified a pid.
argument-list The remaining arguments are passed to your executable application.

Examples

Example: Binding to an already running application

Start your application (firefox in this example) first. Make sure this is an application you wouldn't mind playing with at the moment. Then run RunAppWhenIdle with no arguments to get a list of currently running processes, so that we can get the process-id (pid) of the application.

> ./RunAppWhenIdle.exe
usage:
RunAppWhenIdle.exe [-idle secs] [-pollIdle milisecs] [-pollUse milisecs] [-cpuLimit 0-100] [-pid procId [-resume] | /path/to/executable argument-list]
Pid     ExeFile
0       [System Process]
4       System
440     smss.exe
...
4148    firefox.exe
4988    RunAppWhenIdle.exe

Now let's bind to firefox. (I decreased the idle and polling times to see the effect without having to wait for long.). After you start RunAppWhenIdle, see how the counter is changing when you move the mouse.

> ./RunAppWhenIdle.exe -idle 5 -pollIdle 300 -pollUse 300 -pid 4148
watching process with pid= 4148
suspending process...
waiting for the computer to become idle...
time remaining to idleness: 4.832 secs.

The counter will go down as the time goes by. It will go back to 5.0 secs if you move your mouse or press a key on the keyboard. Note that the process (firefox) is suspended at the moment, and you would not be able to interact with it. Try going to your application (firefox); it will not respond, because it is kept sleeping while you are using your computer.

time remaining to idleness: 0.273 secs.
computer is idle now.
resuming process...

The process is resumed when the computer is idle. As soon as you move the mouse or press a key, the process is suspended again.

suspending process...
waiting for the computer to become idle...
time remaining to idleness: 164 secs.
computer is idle now.
resuming process...

Press Ctrl+C to end RunAppWhenIdle.

Example: Running a new application

You can also specify a new application to be executed by RunAppWhenIdle. Below example runs sleep 10 command, which is a simple program that does nothing for a total of 10 seconds.

> ./RunAppWhenIdle.exe -idle 5 -pollIdle 300 -pollUse 300 sleep 10
waiting for the computer to become idle...
time remaining to idleness: 0.140 secs.
computer is idle now.
running command [sleep "10"]
started application with process id: 1904
watching process with pid= 1904
suspending process...
waiting for the computer to become idle...
time remaining to idleness: 0.149 secs.
computer is idle now.
resuming process...
process with pid=1904 has finished running.

~~DISCUSSION~~