Discussion:
[xmonad] kill -STOP/-CONT hack
Adam Sjøgren
2016-03-10 17:36:07 UTC
Permalink
Hi,


Has anyone implemented this kill -STOP/-CONT hack:

· https://blog.mister-muffin.de/2014/11/07/automatically-suspending-cpu-hungry-applications/

in XMonad?


Best regards,

Adam
--
"Time is getting short; every midnight I feel 48 Adam Sjøgren
hours older. And twice as useless." ***@koldfront.dk
Brandon Allbery
2016-03-10 17:39:01 UTC
Permalink
Post by Adam Sjøgren
·
https://blog.mister-muffin.de/2014/11/07/automatically-suspending-cpu-hungry-applications/
in XMonad?
http://hackage.haskell.org/package/xmonad-contrib-0.12/docs/XMonad-Layout-Stoppable.html
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Adam Sjøgren
2016-03-10 18:07:02 UTC
Permalink
Post by Brandon Allbery
http://hackage.haskell.org/package/xmonad-contrib-0.12/docs/XMonad-Layout-Stoppable.html
Cool! Now I just need to figure out how to only apply it to certain
programs.


Best regards,

Adam
--
"You've got to be excited about what you are doing." Adam Sjøgren
***@koldfront.dk
Adam Sjøgren
2016-06-12 19:53:23 UTC
Permalink
Post by Brandon Allbery
http://hackage.haskell.org/package/xmonad-contrib-0.12/docs/XMonad-Layout-Stoppable.html
I have been looking at the documentation there, and searching around. It
says this is how you use it:

import XMonad
import XMonad.Layout.Stoppable

main = xmonad def
{ layoutHook = layoutHook def ||| stoppable (layoutHook def) }

But. Uhm. What if I only want to apply it to some programs (Firefox), or
one workspace (say, "3")?


Best regards,

Adam
--
"It's part of our policy not to be taken seriously" Adam Sjøgren
***@koldfront.dk
Brandon Allbery
2016-06-12 20:04:43 UTC
Permalink
Post by Adam Sjøgren
But. Uhm. What if I only want to apply it to some programs (Firefox), or
one workspace (say, "3")?
Since it's a layout, you can't apply it to individual windows (or programs
--- in fact you cannot with 100% reliably map a window to a program, by
X11's design). For workspaces, consider XMonad.Layout.PerWorkspace.
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Adam Sjøgren
2016-06-12 21:02:13 UTC
Permalink
Post by Brandon Allbery
For workspaces, consider XMonad.Layout.PerWorkspace.
Thanks for the tip.

The documentation is confusing to me - some places '|||' is used to
combine things, other places it isn't.

Anyway, this is what I tried first:

, layoutHook = avoidStruts $ layoutHook defaultConfig ||| modWorkspace "3" stoppable (layoutHook defaultConfig)

which doesn't seem to work, as the browser running on workspace 3 (mod-3
takes me there), keeps using 5-8% CPU according to top when another
workspace is active.

Taking the example from the XMonad.Layout.Stoppable directly:

, layoutHook = layoutHook defaultConfig ||| stoppable (layoutHook defaultConfig)

doesn't stop the programs on the other workspaces either, so I guess
I've misunderstood something fundamental :-)

(This on Debian unstable, Linux 4.6.1, xmonad, X11, xmonad-contrib from git.)


Best regards,

Adam
--
"Sometimes it pays to stay in bed on Monday, rather Adam Sjøgren
than spending the rest of the week debugging ***@koldfront.dk
Monday's code."
Brandon Allbery
2016-06-12 22:53:41 UTC
Permalink
Post by Adam Sjøgren
The documentation is confusing to me - some places '|||' is used to
combine things, other places it isn't.
||| separates layouts. Layouts are complete in and of themselves.

Other things are layout modifiers. As the name suggests, they modify other
layouts; the layout to be modified is a parameter, and there may be other
parameters which may also be workspaces.

Maybe this will be clearer:

Full -- this is a layout, it can stand by itself or be modified
smartBorders Full -- this is a layout modifier applied to a layout
smartBorders -- this is an error, because it is not applied to a
layout. "It is a purple." -- a purple *what*?
smartBorders ||| Full -- this is an error because you are saying
"either use smartBorders or use Full". But smartBorders is not a layout

, layoutHook = avoidStruts $ layoutHook defaultConfig |||
Post by Adam Sjøgren
modWorkspace "3" stoppable (layoutHook defaultConfig)
which doesn't seem to work, as the browser running on workspace 3 (mod-3
takes me there), keeps using 5-8% CPU according to top when another
workspace is active.
I hate their example because it is not clear that it has all the layouts in
defaultConfig twice and only the second list has the stop behavior. You
need to mod-space 3 times to get to a stoppable layout.

If you want stoppable to always be active on workspace 3:

layoutHook = avoidStruts $ modWorkspace "3" stoppable $ layoutHook
defaultConfig

(I find it interesting that you were able to figure out that modWorkspace
applies only to layout modifiers as opposed to layouts, but you couldn't
recognize that (|||) only works with layouts, not layout modifiers.)
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Adam Sjøgren
2016-06-13 15:43:34 UTC
Permalink
Post by Brandon Allbery
I hate their example because it is not clear that it has all the layouts in
defaultConfig twice and only the second list has the stop behavior. You
need to mod-space 3 times to get to a stoppable layout.
Oh. No, that was very unclear to me. I was wondering about the
duplication, but I glossed it over as yet another subtle point I did not
comprehend.

I guess my point is that expanding the examples - in general - would
help people, like me, get further into these things.
Post by Brandon Allbery
layoutHook = avoidStruts $ modWorkspace "3" stoppable $ layoutHook
defaultConfig
Thanks!

I am trying that now, and it doesn't seem to work for me - the Firefox
on workspace 3 is still using 5-10% CPU, regardless of how long I have
been on another workspace.
Post by Brandon Allbery
(I find it interesting that you were able to figure out that modWorkspace
applies only to layout modifiers as opposed to layouts, but you couldn't
recognize that (|||) only works with layouts, not layout modifiers.)
(Well, I just kept taking stuff from the examples and combining them
until the compiler stopped complaining. I don't have much experience
with Haskell, but I do with debugging/pattern matching/guessing.)


Best regards,

Adam
--
"Come on ask me anything Adam Sjøgren
I'm the king of not very much" ***@koldfront.dk
Brandon Allbery
2016-06-14 21:36:04 UTC
Permalink
Post by Adam Sjøgren
I am trying that now, and it doesn't seem to work for me - the Firefox
on workspace 3 is still using 5-10% CPU, regardless of how long I have
been on another workspace.
I was waiting to see if the author of the contrib would jump in, but I
guess not. (Contribs are contributed, as the name suggests, and we can't
necessarily support all of them directly.)

That said, browsers are likely to be a specific screw case these days
because sandboxing means that windows or even individual tabs may be
running in their own processes (they certainly are in Chrome / chromium).
It is not reliably possible (indeed, not necessarily possible at all) to go
from an X11 window to all the associated processes, especially going in
both directions (that is, downward from a window to tab sandbox processes
*and* up from it to the parent browser process(es)), so stopping the whole
browser is not going to happen and individual tab processes may well keep
running as well, with only the process that created the window itself
stopped. (I can't speak for Firefox, but for Chrome this will be a process
largely independent of all the tabs, other windows, and various other
working processes including any installed apps.) I could also imagine the
browser not handling this well since it might well not expect a single
process in the chain to be stopped (...or it might handle it by sending
SIGCONT on seeing a process come back to waitpid() with WSTOPPED, defeating
the layout modifier).
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Adam Sjøgren
2016-06-14 21:52:14 UTC
Permalink
Post by Brandon Allbery
I was waiting to see if the author of the contrib would jump in, but I
guess not. (Contribs are contributed, as the name suggests, and we can't
necessarily support all of them directly.)
That is, of course, fair. It is ok to discuss contrib stuff on this
mailing list, though, right?
Post by Brandon Allbery
That said, browsers are likely to be a specific screw case these days
because sandboxing means that windows or even individual tabs may be
running in their own processes (they certainly are in Chrome / chromium).
Ok, let's take out the complexity that is webbrowsers and try something
simpler.

If I start another program, say xeyes, on workspace 1, its state is
reported by "ps faux" as 'S', and eyes are following my mouse pointer.

If I then "killall -STOP xeyes", the eyes stop moving, and the state is
reported as 'T' by ps.

When I "killall -CONT xeyes", the eyes move again, and the state is back
to 'S'.

If I move xeyes to workspace 3, the state keeps being reported as 'S' by
ps. It never changes to 'T', even 15 seconds after switching to
workspace 1.

This makes me think that something might not be working in my setup.

This is with:

, layoutHook = avoidStruts $ modWorkspace "3" stoppable $ layoutHook defaultConfig

in my xmonad.hs.

Have I misunderstood what is supposed to happen?


Best regards,

Adam
--
"Sunday morning when the rain begins to fall Adam Sjøgren
I believe I have seen the end of it all" ***@koldfront.dk
Brandon Allbery
2016-06-14 22:00:09 UTC
Permalink
Post by Adam Sjøgren
If I move xeyes to workspace 3, the state keeps being reported as 'S' by
ps. It never changes to 'T', even 15 seconds after switching to
workspace 1.
Wait, are you ever making workspace 3 current in this, or just moving with
mod-shift-3? Layouts don't (and can't) react to the latter; the layout can
only stop and start processes when you switch to or away from a workspace.
The shift operation only manipulates the StackSet without informing the
layout.

(In theory a layout could be notified, but it'd require more layout methods
and those methods would have to guarantee they don't try to draw anything
or manipulate the screen / windows directly because the workspace might not
be current.)
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Adam Sjøgren
2016-06-14 22:11:41 UTC
Permalink
Post by Brandon Allbery
Post by Adam Sjøgren
If I move xeyes to workspace 3, the state keeps being reported as 'S' by
ps. It never changes to 'T', even 15 seconds after switching to
workspace 1.
Wait, are you ever making workspace 3 current in this, or just moving with
mod-shift-3? Layouts don't (and can't) react to the latter; the layout can
only stop and start processes when you switch to or away from a workspace.
Makes no difference either way. Does it work for you?


Best regards,

Adam
--
"Don't give me those sandy metal eyes Adam Sjøgren
'Cause I'm proud, and my hair is nice" ***@koldfront.dk
Brandon Allbery
2016-06-14 22:19:19 UTC
Permalink
Post by Adam Sjøgren
Post by Brandon Allbery
Post by Adam Sjøgren
If I move xeyes to workspace 3, the state keeps being reported as 'S' by
ps. It never changes to 'T', even 15 seconds after switching to
workspace 1.
Wait, are you ever making workspace 3 current in this, or just moving
with
Post by Brandon Allbery
mod-shift-3? Layouts don't (and can't) react to the latter; the layout
can
Post by Brandon Allbery
only stop and start processes when you switch to or away from a
workspace.
Makes no difference either way. Does it work for you?
Haven't tried because I don't have a sandbox setup on this machine (to run
a separate xmonad setup from my main one in xephyr).

I just realized xeyes was a bad choice; Stoppable relies on _NET_WM_PID,
and...

pyanfar «.xmonad*pyanfar» Z$ xeyes & sleep 3; xprop -name xeyes
_NET_WM_PID; kill $!
[1] 14711
_NET_WM_PID: not found.
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Brandon Allbery
2016-06-14 22:23:21 UTC
Permalink
Post by Brandon Allbery
I just realized xeyes was a bad choice; Stoppable relies on _NET_WM_PID,
and...
If you test this with a terminal, use one that doesn't use factory backends
(like xterm or urxvt --- NOT urxvtc!) or suppress the backend factory;
otherwise you get the pid of the factory and will be very unhappy when it
suspends every terminal instance because they're all owned by the factory.
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Brandon Allbery
2016-06-14 22:35:37 UTC
Permalink
Post by Brandon Allbery
Post by Brandon Allbery
I just realized xeyes was a bad choice; Stoppable relies on _NET_WM_PID,
and...
If you test this with a terminal, use one that doesn't use factory
backends (like xterm or urxvt --- NOT urxvtc!) or suppress the backend
factory; otherwise you get the pid of the factory and will be very unhappy
when it suspends every terminal instance because they're all owned by the
factory.
I should also mention that I pointed out these and other shortcomings of
the information any implementation could rely on for this --- which isn't
much --- to the author back when they were writing it. You seem to be
hitting all the pain spots where it can't work sensibly. (Very recent xorg
has a call that could make the xeyes case work, but would not help with the
other cases I mentioned. It would also open an interesting potential issue
with remote windows via ssh X11 forwarding, where it could suspend the ssh
as the apparent owner of the window and cause the remote to time out and
drop the connection.)

X11 *really* does not want this kind of thing to work.
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Adam Sjøgren
2016-06-14 22:56:42 UTC
Permalink
Post by Brandon Allbery
X11 *really* does not want this kind of thing to work.
Maybe the documentation of the module could be amended with a paragraph
outlining this.

(I definitely would not have wasted (your) time trying to get it to run,
if it had.)

Thanks for all the tips!


Best regards,

Adam
--
"It's part of our policy not to be taken seriously" Adam Sjøgren
***@koldfront.dk
Adam Sjøgren
2016-06-14 23:24:58 UTC
Permalink
Post by Adam Sjøgren
Post by Brandon Allbery
X11 *really* does not want this kind of thing to work.
Maybe the documentation of the module could be amended with a paragraph
outlining this.
Putting my keyboard where my mouth is, as a start:
· https://github.com/asjo/xmonad-contrib/commit/b2ecbe7471a5d519fc03288614c6df393cab1e7a
Post by Adam Sjøgren
(I definitely would not have wasted (your) time trying to get it to run,
if it had.)
I don't, however, understand why it doesn't work on Firefox. kill -STOP
manually _does_ work on Firefox. And Firefox sets _NET_WM_PID.


Best regards,

Adam
--
"I say, either agree with me or take a hike! I'm Adam Sjøgren
right, period! End of discussion!" ***@koldfront.dk
Paul Fertser
2016-06-15 06:46:32 UTC
Permalink
Hey Adam,
Post by Adam Sjøgren
Post by Adam Sjøgren
(I definitely would not have wasted (your) time trying to get it to run,
if it had.)
I don't, however, understand why it doesn't work on Firefox. kill -STOP
manually _does_ work on Firefox. And Firefox sets _NET_WM_PID.
I can add another datapoint here: it works with Firefox on my machine,
but the exact config and firefox version will be available only later
today, when I get back home.
--
Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software!
mailto:***@gmail.com
Adam Sjøgren
2016-06-15 11:04:30 UTC
Permalink
Post by Paul Fertser
I can add another datapoint here: it works with Firefox on my machine,
but the exact config and firefox version will be available only later
today, when I get back home.
Cool, that would be fun to see.

(I'm on 45.2.0)


Best regards,

Adam
--
"You make a hit by putting two flops together" Adam Sjøgren
***@koldfront.dk
Paul Fertser
2016-06-20 07:47:55 UTC
Permalink
Sorry for the slow reply,
Post by Adam Sjøgren
Post by Paul Fertser
I can add another datapoint here: it works with Firefox on my machine,
but the exact config and firefox version will be available only later
today, when I get back home.
Cool, that would be fun to see.
(I'm on 45.2.0)
I've seen a report that 47 doesn't work but I haven't tried it myself
yet (I'm in the middle of a system upgrade so I can't even say what
version worked for me). I've tried with starting gqview, moving it to
my stoppable workspace, then switching to that workspace and back and
after 5 seconds gqview was stopped, ps output showed T status.

Here's the relevant part of my config:

layoutHook = modWorkspace "stop" (ModifiedLayout (Stoppable "S" 5 Nothing)) $ reflectHoriz $ layoutHook defaultConfig
XMonad.workspaces = map show [1..8] ++ ["stop"]

(full config attached)

That's with xmonad 0.11.1.
--
Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software!
mailto:***@gmail.com
Paul Fertser
2016-06-20 16:11:38 UTC
Permalink
Post by Paul Fertser
I've seen a report that 47 doesn't work but I haven't tried it myself
Now I can confirm that Firefox 47.0 can be stopped as well. The
report I was talking about was due to running it in firejail.
--
Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software!
mailto:***@gmail.com
Adam Sjøgren
2016-06-20 16:33:40 UTC
Permalink
Post by Paul Fertser
Post by Paul Fertser
I've seen a report that 47 doesn't work but I haven't tried it myself
Now I can confirm that Firefox 47.0 can be stopped as well. The
report I was talking about was due to running it in firejail.
Ok, thanks for checking!

Nothing gets stopped for me (even when trying something different from
xeyes, say, eog, which does set _NET_WM_PID), so I'm probably doing
something wrong.

I am running xmonad and xmonad-contrib from the development repository,
though, and this layoutHook:

layoutHook = avoidStruts $ modWorkspace "3" stoppable $ layoutHook defaultConfig


Best regards,

Adam
--
"Why should they care Adam Sjøgren
With bitter eyes ***@koldfront.dk
They've already paid the price
Money always takes the place of life"
Daniel Wagner
2016-06-23 21:38:33 UTC
Permalink
Post by Adam Sjøgren
·
https://github.com/asjo/xmonad-contrib/commit/b2ecbe7471a5d519fc03288614c6df393cab1e7a
If you can turn this change into a clean, one-commit pull request against
xmonad/xmonad-contrib, I'll happily merge it. Or I'll be happy to make the
change myself if you don't care about attribution in the git log.
~d
Adam Sjøgren
2016-09-03 21:44:43 UTC
Permalink
Post by Daniel Wagner
If you can turn this change into a clean, one-commit pull request against
xmonad/xmonad-contrib, I'll happily merge it.
Done now (still learning the whole pull request game):

· https://github.com/xmonad/xmonad-contrib/pull/81


Best regards,

Adam
--
"Where there's a will, there's a won't" Adam Sjøgren
***@koldfront.dk
Continue reading on narkive:
Loading...