6 ms·
Pause/unpause any X11 application
- emilfihlman 8y agoThis is seriously cool idea. But could you not get the same effect with nice?
- c0l0 8y agoNo, you cannot. A given task, running at maximum "niceness" (i.e., the lowest "priority" in regard to its peers) will happily consume 100% CPU if it has enough work to do - at least in total absence of other consumers of that resource. SIGSTOP effectively tells the scheduler to just not allocate any CPU time to the task any more, which makes the task unable to perform any work (and also not consume any additional resources, of course).
- comboy 8y agoAwesome, for those of you wondering just like me - it's SIGCONT.
- vermaden 8y agoThanks. The `nice` (or also `idprio` on FreeBSD) will only lower the priotiry in the queue for CPU time, which means that if nothing else will need CPU it will still get as much CPU time as it wants, thus still eating battery time.
- kjeetgill 8y agoSigstop is pulling the car over. Nice is like pulling over if there's other traffic on the road but going full speed ahead if it's empty.
- saagarjha 8y agoIt’s interesting to see that stopping a process causes visual artifacts when a window on top of it is moved. This is really odd, since it seems like applications should be able to affect each other in that way; that is, this not isolated so that a frozen window shows a snapshot of how it looked when it was sent the signal and nothing else?
- rhn_mk1 8y agoThat depends on the window manager. The application state is not really affected, it just stops updating (redrawing its area). When another window moves away, the window manager asks the "underlying" application to update that area of the screen. It's dead, so the WM keeps displaying the last thing that was there, until something else happens in that spot. On the other hand, compositing window managers will dedicate a separate buffer to each application, where they have exclusive access. That kind of a window manager would not have to ask the application to update anything - it would just take the image from the dedicated application's buffer and update the screen with it. Since the application's buffer can't be modified by anything else, it would have the last state of the application in it. That would in turn find its way to the screen. No glitches.
- oh5nxo 8y agoIt also partially depends on how the client program has configured her windows, and how the X server handles related stuff.
- imglorp 8y agoYour sleep command could also iconify/minify the app's windows.
- vermaden 8y agoGood idea. Just added -A and -S options that also minimize a window. -a - Do pause/resume active window. -A - Do pause/resume active window and minimize it. -s - Do pause/resume interactively selected window. -S - Do pause/resume interactively selected window and minimize it. https://github.com/vermaden/scripts/commit/03591a138b14cededa15a05fe9c77bf1a941795d https://github.com/vermaden/scripts/commit/03591a138b14ceded...
- pjc50 8y agoHandy, although that's not how I was expecting it to work - SIGSTOP is all well and good, but what if your window is coming from a remote system? Or does nobody use ssh X forwarding any more? What I was expecting was a means of suspending the X event loop, so the application remains "running" but idle.
- mcny 8y agoThere's a machine I should into but I don't know if I can x inner ssh because it isn't publicly available. I ssh into another machine and then ssh from there to that machine. I don't even know how to search this question. The machine in the middle doesn't have a display. X over ssh is difficult.
- 0x0 8y agoTry setting up a $HOME/.ssh/config entry for the inner machine and specify a ProxyJump command referencing the outer machine? It should end up relaying a direct ssh connection across the outer ssh session's TCP port forwarding mechanism (I think)
- pjc50 8y agoIt can work if X forwarding is enabled on both hops. However, X11 forwarding may be disabled in the sshd_config on the remote system. It doesn't require a physical display. If it's working then it should set the $DISPLAY environment variable inside the ssh session.
- dfox 8y agoAnother thing that is required for X11 forwarding is installed xauth on the server side (that means even the middle host(s)), nothing else X11 related is required.
- klibertp 8y ago> Or does nobody use ssh X forwarding any more? For a few years I worked with a bit of peculiar setup: I had a laptop with Windows and Xming (X impl for Win) and a headless desktop with FreeBSD under my desk. I didn't actually use SSH X forwarding - if I remember correctly, I configured it such that X apps run on the desktop would display on my laptop communicating over LAN with a raw X protocol. So I would SSH under my desk and run gVIM, RXVT and a few other tools which displayed as windows on Win. It was cool in more ways than one, but - even in that setup - the latency, or lag, between a keystroke and the effect, was visible and occasionally irritating. It was still much better than doing the same over SSH - which was the reason why I opted for the insecure open-to-the-world X setup in the first place - and that was over a wire less than 2 meters long. Needless to say, the lag when working on remote servers over SSH was much greater than that. It was kind of OK for displaying things which (optionally) updated on their own once a second or things like that, but I would be very unhappy, to the point of quitting after a week, if I had to actually work over such a connection. Well, maybe I'm exaggerating and I could get used to it - still, the experience, when compared to running things locally or remotely, but in terminal (ie. VIM instead of gVIM), can be summarized with one word: LAG. Lots and lots of it :)
- oever 8y agoIt would be wonderful to have a pause button on the titlebar of applications.
- vermaden 8y agoIts totally possible :)
- imglorp 8y agoGreat idea. Probably needs to be WM dependent. I started looking at the Gnome path and realized adding a window title bar menu item is probably easier, because they seem pretty locked into the Big Three buttons, and you'd get into layout and icon issues.
- owaislone 8y agoVery cool. I tried it on KDE Neon (ubuntu 18.04) and it worked perfectly. Didn't even leave any artifacts. However, all input events were queued up by KWin and as the application handled them as soon as I resumed it. Would be seriously cool if KWin natively supported this so apps would truly freeze. Would fit in perfectly with Plasma's Activity system.
- geokon 8y agoYou can suspend a whole Plasma activity already. Isn't that more useful?
- owaislone 8y agoReally? I've never noticed it. Apps running in another plasma activity always show up as running instead of stopped and continue to consume resources. I only tested by switching between activities.
- geokon 8y agoThey don't suspend by default. I don't use KDE any longer so maybe it's changed, but you just needed to right click on the activity in the activity panel and there should be a menu item to suspend the whole activity. It's really a non-obvious feature.. :) It's very handy and it's the main thing I miss from KDE b/c you can have more stuff "running" on a wimpy computer. I'd usually have a whole activity for some project I only touch once a week and it'd just sits suspended in the background till I needed it again
- BagOfPistchios 8y agoThe only times I have ever wanted to freeze an application it was for the purpose of it not hogging CPU time in favor of some interactive program, and had no better way of doing that. On Linux, the Con Kolivas MuQSS CPU scheduler introduces a new scheduling policy called SCHED_IDLEPRIO which runs a program only if there is absolutely nothing else to run. It is perfect for long-running programs that don't need interactive performance. EDIT: The example given in this article is also IMO better solved by using SCHED_IDLEPRIO >Other example may be some heavy processing. For example you started RawTherapee or Darktable processing of large amount of photos and you are not able to smoothly watch a video. Just pause it, watch the video and unpause it again to finish its work.
- Uplink 8y agoI'm nitpicking, but is there a reason why you use the numeric signal number in Linux? On my machine "kill -SIGSTOP" works as expected, and I don't remember a time when you couldn't use signal names like that.
- vermaden 8y agoOne thing about the title, its not `xdotool` that does the pause/unpause, the `xdotool` is used only to get PID of active application with -a option. Same with -s option where you will select the target window with `xprop` command. The pause/unpause is done by the `kill` command of course. This title was not set by me.
- pbhjpbhj 8y agoApropos of nothing, you can use xdotool for rudimentary gui macros like very simple game bots and such. Your post made me think perhaps xkill had an option to send other signals than abort, but it doesn't appear to without modification.
- jolmg 8y agoI believe xkill doesn't send any signals at all. Rather it tells the x-server to destroy a window and close its connection with the program that opened the window. If programs die, it's only because they weren't expecting their connection to suddenly be closed, as most wouldn't.
- auscompgeek 8y agoHeh, nice. I also wrote a simple script a long while ago, after someone wrote Universal Pause Button for Windows. https://gist.github.com/auscompgeek/5da8f27e50feb185d1e2 https://gist.github.com/auscompgeek/5da8f27e50feb185d1e2 There are a couple of functional differences I can see: - I directly read /proc to grab the current process status, which probably isn't very portable... - vermaden's will also stop the children of the process. Unfortunately I don't really use this any more, since I use Wayland these days.
- grapeli23 8y agoThe cgroup freezer is much better (reliable). https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/cgroup-v1/freezer-subsystem.txt https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...
- vermaden 8y agoIn what way its more reliable? It works only on Linux. Mine approach works on Linux/FreeBSD/OpenBSD/Illumos/Solaris/UNIX/...
- stubborn_d0nkey 8y agoMore reliable not more available. It's because programs in userspace can mess with the signal usage, while they can't with the cgroup feezing.
- blueyed 8y agoSounds interesting, and I've created a note to look into this for my recipe that I use with awesomeWM (https://github.com/awesomeWM/awesome-www/pull/111/files https://github.com/awesomeWM/awesome-www/pull/111/files). However at first glance it is much more difficult to setup (cgroups permissions, creating task groups etc). I wonder if there is a wrapper that would behave more like "kill -STOP" already?
- hultner 8y agoThis is actually very neat, I haven't though about pausing desktop applications to save battery/CPU before. Tried it out real quick with Safari on my work laptop (macOS), worked like a charm with killall -STOP "Safari" Safari is paused/suspended killall -CONT "Safari" Responding again. Shouldn't be to hard to hook it up to a keyboard shortcut which grabs the active window and sends stop/continue signals to that window.
- vermaden 8y agoThe `xdotool` is available in the https://brew.sh https://brew.sh so you can just use the provided `desktop-pause.sh` script with a shortcut which does exactly that - "grabs the active window and sends stop/continue signals to that window".
- hultner 8y agoDoes this work for Aqua applications as well? I'm thinking we'd like to use something like Hammerspoon or AppleScript to fetch the PID of the currently focused window. https://www.hammerspoon.org https://www.hammerspoon.org
- pbhjpbhj 8y ago>Can you imagine opening xterm(1) terminal and searching for all Chromium or Firefox processes and then freezing them one by one every time you need it? Me neither. I can, "pkill -STOP firefox"? pkill takes regex too. Y'all have heard of ctrl+z too I hope.
- vermaden 8y agoYou are right about pkill. About CTRL-Z and other of these I once wrote about them :) https://vermaden.wordpress.com/2018/07/08/ghost-in-the-shell-part-2/ https://vermaden.wordpress.com/2018/07/08/ghost-in-the-shell...
- pbhjpbhj 8y agoYour style is really easy to read, but I thought you meant there was something wrong with ctrl+z : thought I was going to get schooled! Nice blog posts, well done.
- dingaling 8y ago> I can, "pkill -STOP firefox"? That doesn't stop Firefox's separate rendering processes, though. They run with the process name Web Content.
- blueyed 8y agoThis is really useful, especially for browsers. I've created a WIP recipe for awesomeWM a while ago, which supports stopping special clients (browsers, thunderbird, slack) after a given timeout of being unfocused, and also when minimizing them. https://github.com/awesomeWM/awesome-www/pull/111/files https://github.com/awesomeWM/awesome-www/pull/111/files
- fabiospampinato 8y agoThis is great! I've just added support for this to my Phoenix [1] setup. [1] https://github.com/fabiospampinato/phoenix https://github.com/fabiospampinato/phoenix