I am noticing that recently my laptop does not go to sleep/lockout after its configured X minutes of inactivity like it did in the past. I suspect some program (like media player does) is preventing it from going to sleep. I do not have any media player running, so how can I find which program is preventing it from sleeping?
It does go to sleep if I close the lid. But I would also like for it to go to sleep after X minutes of inactivity.
Update: Upgraded to Ubuntu 18.04 with default Gnome and Wayland enabled.
I think I figured it out.
I used:
to get the list of inhibitors, like:
Then I did:
Which returned:
It seems Firefox is preventing it. It seems that now when YouTube is playing it prevents sleeping.
Mitar is definitely the right answer, you can use dbus to retrieve the information.
The interesting aspect of it is that some tabs in Firefox will create the problem and others do not. As I tested now I can tell it's smart enough to add/remove the inhibition depending on the content of the page—i.e. on YouTube you have a video, that inhibits the screensaver.
I wrote a script in PHP in order to list the inhibitors as a simple list. I bet there are tools/libraries in python to do that (because many of the OS code uses that language) but unfortunately I don't know python enough to do that.
Copy the following in a file such as
~/bin/inhibitors
and then make it executable withchmod 755 ~/bin/inhibitors
. Now in your console you can type:inhibitors
and you get a list of tools preventing your OS from going to sleep.Here is an example of output:
In this case Firefox and Totem block my screensaver.
This D-Bus command should work with any freedeskop-compliant power manager:The following works only in XFCE
The output was:
Based on the answer from Alexis Wilke, I created a python solution:
https://pypi.org/project/list-session-inhibitors/
I have activated the Caffeine plugin, the Franz messaging app and I am running two Google meets in different accounts, one in Firefox and one in Chrome.
My script produces output like this:
An alternative is
systemd-inhibit --list
but is not as helpful.:If you open a terminal window you can type "top" to view a continuously updating list of all running processes. One of these busy background processes is stopping your laptop from going to sleep. For a static list type "ps aux" instead. You can then see their process identification numbers. This will allow you to use "sudo kill pidnumber" on any suspect process, to see if stopping it will then allow your laptop to go to sleep (after its timeout period). Once you have identified the problematic process, you can then make an informed decision about whether that process is important to you.