Join us on the Linux Gaming community on Lemmy, the federated open source alternative to Reddit.
A bash script to pause/resume games:
kokoko3k 3 days ago
Hi there,
I just made a little handy script I'm using lately, it is named

His function is to pause and resume whatever program running in a X11 window.

Not all games support a pause function when unfocused, and this is not good for power consumption.
In other ones you may want to just stop them for whatever reason (take some time to translate a string -eg: in gta5 when there are subtitles in foreing language while you're driving, cheating... whatever).
I just paused Horizon Chase Turbo to write this post and let my cpu and gpu rest for a while :)

Usage: Action Target

       ask: Ask to pause or continue execution (uses kdialog to ask you what to do)
    switch: Switch execution state paused <-> running

    active: Use the active window (pause or resume the active window)
    select: Ask user to click on a window (expects you to click on the window you want to pause)

  • The program to freeze has to be running into an X11 window implementing _NET_WM_PID property
  • xprop
  • awk
  • xdotool (only to use the "select" function)
  • kdialog (only to use the "ask" function)

Currenty, i've bound " switch active" to a SHIFT+PAUSE hotkey (use whatever tool your de provides to assign custom commands to shortcuts), so that while i'm playing, i hit SHIFT+PAUSE and have my game paused or resumed.

Beware that for how Xorg works, when not using a compositor, when a window is "paused" it does not update his content, so if you minimize the window and restore it while paused, it will be totally black. Also if it is partially obscured by another one, the latter will leave traces on it (win95 effect); resuming the window will make them go away.

Oh, it doesn't work for all the programs, because sometimes their window doesn't implement _NET_WM_PID and I wasn't able to resolve a window id to a pid in those cases, not even xkill is able to work on them, but fortunately they are rare.

Here it is:
#!/usr/bin/env bash

# [ask|switch] [active|select]

# ask = ask to pause or continue execution
# switch = switch execution state

# active = use the active window
# select = ask user to click on a window

if [ $2 = "active" ] ; then
        PROC=$(xprop -id $(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}') | awk '/_NET_WM_PID\(CARDINAL\)/{print $NF}')
        PROC=$(xdotool selectwindow getwindowpid)

if [ $1 = "ask" ] ; then
        kdialog --yesno $(</proc/$PROC/comm) --yes-label RESUME --no-label PAUSE
        grep State: /proc/$PROC/status|grep stopped
echo $condition_continue 

if [ $condition_continue = 0 ] ; then 
        echo cont
        kill -CONT $PROC
        echo stop
        kill -STOP $PROC

#cat /proc/$PROC/status #debug

Hope someone will find it useful,
back to Horizon Chase Turbo, cheers!

Last edited by kokoko3k on 22 July 2021 at 4:21 pm UTC
stan 3 days ago
  • Supporter
Oh, nice idea! I think I’m going to try it.
While you're here, please consider supporting GamingOnLinux on:

Patreon, Liberapay or PayPal Donation.

This ensures all of our main content remains totally free for everyone with no article paywalls. We also don't have tons of adverts, there's also no tracking and we respect your privacy. Just good, fresh content. Without your continued support, we simply could not continue!

You can find even more ways to support us on this dedicated page any time. If you already are, thank you!
Login / Register

Or login with...
Sign in with Steam Sign in with Twitter Sign in with Google
Social logins require cookies to stay logged in.

Livestreams & Videos
Community Livestreams
Latest Forum Posts