Pause programs when not in foreground?

Any other tech-related topics
Post Reply
Message
Author
User avatar
webfork
Posts: 10821
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Pause programs when not in foreground?

#1 Post by webfork »

Disclaimer: native process freezing in Windows may cause the program to crash or other issues. I'm asking because I'm comfortable breaking things.

---

Having noticed a number of programs on my machine taking up a lots of processor while not really doing anything, I started thinking about ways to cap that.

Is there a way to pause or freeze a given program or programs when not actively in the foreground/selected? Or like 10 seconds after it's minimized on the interface? There's a way to do this manually: https://www.howtogeek.com/199976/how-to ... -explorer/ but the only other option I've seen here is to run software inside a virtual machine and then pause the virtual machine when not in use. This requires a lot of RAM and I think VirtualBox is CTRL+SHIFT+P.

The only problem is that the general CPU overhead of running virtualization software on top of everything else might make this more wasteful in the long run.

One alternative is to setup "traps" for process affinity using Daphne, restricting it to one processor core and locking to an absolute cap of 25% if you have a 4-core processor like me.

Related topics

* InternetOff

User avatar
Andrew Lee
Posts: 3061
Joined: Sat Feb 04, 2006 9:19 am
Contact:

Re: Pause programs when not in foreground?

#2 Post by Andrew Lee »

Correct me if I am wrong, but I think the purpose of the suspend function is more for debugging a process, and not really for use in the way that you have described. Suspending a process that you do not own is not without its risks. See https://j00ru.vexillium.org/2009/08/sus ... n-windows/:
Despite this technique is working well in most cases, the following cons must be taken into account:

- There are many multi-threaded applications, that take advantage of thread operations’ order. In case such a program would get suspended in a wrong execution moment, some unpredictable behaviour could be expected (in worst case – a simple deadlock or process crash) – it is practically very dangerous approach.

- A race condition could happen under some specific circumstances. When half of the threads would have been already suspended, one of the upper-half threads could try to create a new one, being placed among these already handled. This would allow further program execution, resulting in unknown (depending on the application itself) behaviour.

- Even though the process that has all of its threads suspended could be considered “inactive”, it is not really true. It is still possible to create a remote thread in the target process’ context – such a situation could take place, for example, when CSRSS decides to create a callback routine in our console application (resulting in having the registered console handlers executed).
The preferred way is to give these processes lower CPU priority and/or bind them to just 1 CPU core. Even more important is to figure out why they are doing this and whether there are any workaround.

For my own experience, I have only consistently encountered this with web browsers, because they can execute arbitrary code. I install an addon to automatically suspend web pages that I have moved to the background for more than x minutes, and that seemed to have mostly mitigated the problem.

I sometimes have processes that run amok and hog the CPU (eg. the system print spooler), but those are glitches rather than a persistent behaviour, and can be resolved by restarting the process.

User avatar
webfork
Posts: 10821
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: Pause programs when not in foreground?

#3 Post by webfork »

Andrew Lee wrote: Fri Jul 15, 2022 4:19 am Correct me if I am wrong, but I think the purpose of the suspend function is more for debugging a process, and not really for use in the way that you have described. Suspending a process that you do not own is not without its risks.
You're 100% right -- I'm breaking the rules and I don't care what apps get hurt in the process. I've lost all sense of decorum as my device fan continues to spin on a computer that has enough horsepower to encode all of Toy Story 1 in 6 hours. Or something.

But yeah I hope nobody coming across this thread thinks this is a good idea. I'll add something to my original post.
I have only consistently encountered this with web browsers, because they can execute arbitrary code. I install an addon to automatically suspend web pages that I have moved to the background for more than x minutes, and that seemed to have mostly mitigated the problem.
Very interesting. Could you post or link to that?

User avatar
Andrew Lee
Posts: 3061
Joined: Sat Feb 04, 2006 9:19 am
Contact:

Re: Pause programs when not in foreground?

#4 Post by Andrew Lee »

webfork wrote: Fri Jul 15, 2022 10:40 am Very interesting. Could you post or link to that?
I am currently using Tiny Suspender on Vivaldi and Chrome.

There are quite a number of similar Firefox addons as well eg. New Tab Suspender.

freakazoid
Posts: 1212
Joined: Wed Jul 18, 2007 5:45 pm

Re: Pause programs when not in foreground?

#5 Post by freakazoid »

Andrew Lee wrote: Fri Jul 15, 2022 8:58 pm I am currently using Tiny Suspender on Vivaldi and Chrome.

There are quite a number of similar Firefox addons as well eg. New Tab Suspender.
I use Auto Tab Discard instead on both FIrefox and Chromium browsers.
is it stealth? ;)

User avatar
webfork
Posts: 10821
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: Pause programs when not in foreground?

#6 Post by webfork »

Andrew Lee wrote: Fri Jul 15, 2022 8:58 pm There are quite a number of similar Firefox addons as well eg. New Tab Suspender.
I like it! Thanks

Image

Post Reply