Skip to content

Instantly share code, notes, and snippets.

@Wizek
Last active November 28, 2016 23:18
Show Gist options
  • Save Wizek/f9dbed868b5da9820f07fd62acc584fd to your computer and use it in GitHub Desktop.
Save Wizek/f9dbed868b5da9820f07fd62acc584fd to your computer and use it in GitHub Desktop.

Anyone knows of a tool to automatically suspend processes for games (or any specific apps) when they get minimized on Windows? If not, would anyone be interested in collaborating on an open source solution to do that?

I like multitasking quite a lot, jumping in and out of games and applications. Even with an SSD I don't like to wait for software to start up, especially games. Many software are written well enough that when they are in the background, e.g. minimized they use less resources such as CPU. But some aren't and that drives me a bit crazy.

"Why do you have to constantly eat 7%/20%/80% of my CPU while you are doing nothing in the background, mister?"

 

I've written a proof of concept for Linux, which works quite as intended:

Usage:

$ ./sleep-in-background.sh "java"
asleep: .95, awake: .05
^C      Exiting: continuing $lastKnownPid (51130)

The above example looks at the command line for the current window's process, and if it contains "java" in it, remembers the process id. When the user window focus changes, it issues a SIGSTOP to the remembered PID. When the focus returns to the remembered PID's window then a SIGCONT is sent. Basically this is what it does on a high level.

Source code: https://gist.github.com/Wizek/4a9084bbe2d9a20fa94d8fc65e75f53e

 

I've also begun to write a similar piece of code for Windows: https://gist.github.com/Wizek/bb942da3de6b4a0f2ff175d9c2b1742f

Then it occurred to me to ask around here just in case.

Especially since I have less experience using Windows APIs than I'd like for writing this.

  • Does anyone of you know about something that is able to suspend applications fully or mostly while they are in the background/minimized/out-of-focus on Windows, and resume them as soon as I focus them again? I know Windows does some CPU throttling already for out-of-focus processes, but I am looking for something more insistent -- like the bash script above that reduces background CPU usage by ~95%.

  • And if not, I'd like to gauge interest, would something like that sound useful to you too? That may motivate me to work on this even by myself.

  • Or even better, would this sound useful enough to you that you would be interested in collaborating on this in a GitHub repository?

@tombiddulph
Copy link

I'd be interesting in collaborating with you. My primary skill set is .NET

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment