Prevent stand-by temporarily?
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Prevent stand-by temporarily?
Hello,
my PC is going into stand-by after 10 minutes, like it's supposed to do. Unfortunately it does so no matter what, even when downloading a large file or doing some computation. The simple trick is to just start a video/audio, that will prevent stand-by, but is quite inconvenient (you have to turn volume down etc.). When I remotely accessing my PC to start a computation this even more annoying.
Isn't there a simple tool called that prevents stand-by, that could be used like this:
nosleep
some-long-computation
killall nosleep
or maybe
nosleep command
That will run the the command and prevent sleep until exit. Does anything like this exist? All I could fine is "you change the setting and change it back". This is not what I want. A media player without root privileges can prevent stand-by, isn't there a tool that can do the same without the need of playing a video?
Best regards
Stefan
my PC is going into stand-by after 10 minutes, like it's supposed to do. Unfortunately it does so no matter what, even when downloading a large file or doing some computation. The simple trick is to just start a video/audio, that will prevent stand-by, but is quite inconvenient (you have to turn volume down etc.). When I remotely accessing my PC to start a computation this even more annoying.
Isn't there a simple tool called that prevents stand-by, that could be used like this:
nosleep
some-long-computation
killall nosleep
or maybe
nosleep command
That will run the the command and prevent sleep until exit. Does anything like this exist? All I could fine is "you change the setting and change it back". This is not what I want. A media player without root privileges can prevent stand-by, isn't there a tool that can do the same without the need of playing a video?
Best regards
Stefan
Last edited by LockBot on Tue Aug 08, 2023 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Prevent stand-by temporarily?
On Xfce's "Power Manager Plugin" as present by default in the tray you can click and set 'Presentation Mode'. If you don't use the Xfce edition: relatively sure that Cinnamon/MATE will have something similar?
Also possible:
Also possible:
systemd-inhibit <command>
Re: Prevent stand-by temporarily?
In Mate there is a panel applet called Inhibit Applet. Right-click an empty spot on your panel and click Add to panel
edit: why is that image so big?!
edit: why is that image so big?!
If you think the issue is solved, edit your original post and add the word solved to the title.
Re: Prevent stand-by temporarily?
No far from that.. the image is enlarged beyond its pixel size in the forum.. probably a pphbb thing.Are you on a 4K display?
If you think the issue is solved, edit your original post and add the word solved to the title.
Re: Prevent stand-by temporarily?
Let us not furthermore muddy the thread, but just in case you with that "enlarged beyond its pixel-size in the forum" in fact mean that: for me the (588x538) picture when saved is exactly as large when viewed on the forum as when viewed through an external viewer, and both exactly right in relation to the 1920x1080 of my desktop. If not for you I'd say you have some weird browser-sides scale factor configured somewhere...
Re: Prevent stand-by temporarily?
I'm on Cinnamon and found a similar applet, but it's not exactly what I want:
- I want to prevent stand-by not screensaver (screen should turn off)
- I also want something that works from the console
Re: Prevent stand-by temporarily?
As mentioned,
systemd-inhibit <command>
(although I don't know if on your setup this keeps "the screensaver" active). man systemd-inhibit
for more info.Re: Prevent stand-by temporarily?
Two problems:
- Doesn't work from SSH:
Failed to inhibit: Access denied
. Same user on desktop terminal no access problem - Doesn't work at all. If I start a process with systemd-inhibit system goes standby just like normal (and that process is listed as block by
systemd-inhibit --list
).
Last edited by stefan_o on Thu Feb 09, 2023 7:50 am, edited 1 time in total.
Re: Prevent stand-by temporarily?
There is another way to disable all sorts of sleep modes but it needs sudo.
To turn all forms of sleep off:
and to turn them back on again:
Got it from here: https://blog.wijman.net/disable-suspend ... -in-linux/
To turn all forms of sleep off:
Code: Select all
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Code: Select all
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
If you think the issue is solved, edit your original post and add the word solved to the title.
Re: Prevent stand-by temporarily?
I don't want enabling/disabling something, just blocking. Otherwise in case of a crash etc. it won't get enabled again
Re: Prevent stand-by temporarily?
Well, it is basically what you asked for:
When you have a computer crash in the middle of the long-computation I think having the sleep modes turned off is the least of your worries anyway.nosleep
some-long-computation
killall nosleep
If you think the issue is solved, edit your original post and add the word solved to the title.
Re: Prevent stand-by temporarily?
There is a subtle difference: With
I also don't necessary mean a computer crash, but maybe a script issue that causes the second command not to be executed.
killall nosleep
I terminate the process, which means at least after a reboot it will go back to sleep like normal if that's not done (nothing changed permanently). Also this should be possible without root access.I also don't necessary mean a computer crash, but maybe a script issue that causes the second command not to be executed.
Re: Prevent stand-by temporarily?
The "from SSH" thing is a mere polkit issue which you could if you so wanted configure out -- but I confirm that it doesn't work at all on at least Mint 21.1 Xfce. The xfce4-power-manager still puts the system to sleep after whichever time is configured in the /xfce4-power-manager/inactivity-on-ac or -on-battery xfconf key also with a sleep inhibitor lock taken.
Pardon, dunno. Undoubtedly an issue again of battling freedesktop.org specifications and/or reality -- but a Google search finds only converse desires and I don't have the time to try and dig deeper.
Pardon, dunno. Undoubtedly an issue again of battling freedesktop.org specifications and/or reality -- but a Google search finds only converse desires and I don't have the time to try and dig deeper.
Re: Prevent stand-by temporarily?
Yes I agree. I have to think this over while having a good lunch because the only solution I can think of now is buying a cheap Chinese mouse that always keeps your system awake unless you switch it off..There is a subtle difference
If you think the issue is solved, edit your original post and add the word solved to the title.
Re: Prevent stand-by temporarily?
Or a regular mouse and an electric toothbrush...
Re: Prevent stand-by temporarily?
A bluetooth-controlled toothbrush...
Sometimes I access my PC via SSH (after using Wake-on-LAN), but it will go back sleep after 10 minutes. Sometimes this is what should happen (I just copy some small file), sometimes not, I start a computation, copy a large file over a slow network etc.
There should be a simple way to temporarily disable sleep. How do video players manage that? Or is there some detection in Cinnamon that there is audio or video playing and therefore stand-by is disabled?
Re: Prevent stand-by temporarily?
I am afraid there is no simple way, here is one using systemd.
Make a new systemd service by creating this file
Enable it with:
Create a script called
Don't forget to make it executable
The systemd change may need a reboot, I am not sure.
Now, when you need sleep to be suspended just type
in the terminal (
I you don't kill it, it won't survive a reboot, so things will return to normal.
Explanation: The systemd service you created will be run at the moment the system tries to go to sleep. If the Execstart command ends with return code other than 0, the system wil not go to sleep.
The command ps -ae | grep "nosleep" looks for a process named nosleep and if it finds it creates return code 1.
Warning: I didnt test this myself.
Found it here: https://unix.stackexchange.com/question ... -connected and that was copied from here: https://bbs.archlinux.org/viewtopic.php ... 0#p1380080
Edit: added else and redirection to /dev/null to suppress the output
Make a new systemd service by creating this file
/etc/systemd/system/dontsleep.service
as superuser/admin containing:
Code: Select all
[Unit]
Description=Inhibit suspend in case of [some] activity
Before=sleep.target
[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c 'if ps -ae | grep "nosleep" > /dev/null; then exit 1; else exit 0; fi'
[Install]
RequiredBy=sleep.target
Code: Select all
systemctl enable dontsleep.service
/home/username/bin/nosleep
and paste this in it:
Code: Select all
#!/usr/bin/bash
sleep infinity
Code: Select all
chmod +x
Now, when you need sleep to be suspended just type
Code: Select all
nosleep &
&
sends it to the background). Start your lengthy computing and afterwards type:
Code: Select all
killall nosleep
Explanation: The systemd service you created will be run at the moment the system tries to go to sleep. If the Execstart command ends with return code other than 0, the system wil not go to sleep.
The command ps -ae | grep "nosleep" looks for a process named nosleep and if it finds it creates return code 1.
Warning: I didnt test this myself.
Found it here: https://unix.stackexchange.com/question ... -connected and that was copied from here: https://bbs.archlinux.org/viewtopic.php ... 0#p1380080
Edit: added else and redirection to /dev/null to suppress the output
If you think the issue is solved, edit your original post and add the word solved to the title.
-
- Level 8
- Posts: 2223
- Joined: Wed Aug 14, 2019 1:02 am
Re: Prevent stand-by temporarily?
Hi, my idea may not be what you want, but my first reaction is: why not create a silent audio or video file just for this purpose, then at least you don't have to turn down the volume for it.