Score:2

Force suspend when closing lid

us flag

Some oppened apps (such as teamviewer or chrome when on an teleconference website) seems to prevent my laptop from going to sleep when I close the lid.

How to force laptop to go to sleep(=suspend) when I close the lid ?

ENV: ubuntu 20.04 on a thinkpad t14s

ng flag
This is an interesting problem. What would motivate you to want your laptop to suspend in the middle of a teleconference?
n0tis avatar
us flag
No matter whatever softwares is running, when I close my lid and throw my laptop in my backpack, I want it suspended not to get hot. Closing all my. apps beforehand is tedious.
Score:1
zw flag

systemd-inhibit --list --mode=block

will list you all the apps that will prevent suspend/hibernation.

The only way to "force" a suspend will be to write a script that will "kill" these apps.

In xfce that would include the xfce4-power-manager who is responsible for checking if someone inhibits - so there should be exceptions from the rule.

The answer of the call above will provide you with the app name and its pid. If killing an app this way is a good idea was not asked by the OP.

You'd have to connect that script to the "lidClose" acpi call or create a systemd service that will be executed before suspend:

[Unit]
Before=suspend.target
[Service]
Type=simple
StandardOutput=syslog
ExecStart= yourScriptHere
[Install]
WantedBy=suspend.target
n0tis avatar
us flag
Thanks, but does not work: google-chrome, when in my visioconfernece website (https://kmeet.infomaniak.com/) is blocking susped but does not show up in `systemd-inhibit --list --mode=block`
n0tis avatar
us flag
Edit: actually a new line DOES appear in this command output, but it's PID is not as expected, it's the one from "gnome-session-binary", killing it results in a chrome crash :/
kanehekili avatar
zw flag
what about `killall "google-chrome"` ? It'll sandbox your apps, so you won't see them process wise
n0tis avatar
us flag
1. I don't want to kill chrome if it's not runnig any sleep blocking 2. "systemd-inhibit --list --mode=block" dives out a generic gnome PID with no way to know it's due to chrome. 3. this program seems to be able to list chrome blocking by it's appID https://pypi.org/project/list-session-inhibitors/ 4. now I just have to find a way to kill an app knowing only it's app ID, which is probably doable, will try when I have time.
kanehekili avatar
zw flag
Report back. I'd be interested in your solution
kanehekili avatar
zw flag
Correct. This will certainly work. But I didn't recommend it, because this bypasses any "driver cleanups" systemd/pm-suspend will do. Try this with a NVIDIA card and it won't come back on resume
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.