Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Zoom in Systemd Cgroups on Linux. Change the max allocations to fit your workstation.
#!/usr/bin/bash -xe
cat <<EOF > "${HOME}/.config/systemd/user/zoom.slice"
[Slice]
AllowedCPUs=0-4
MemoryHigh=6G
EOF
cat /usr/share/applications/Zoom.desktop | sed -E 's#^(Exec=).*$#Exec=/usr/bin/systemd-run --user --slice=zoom.slice /opt/zoom/ZoomLauncher#' > "${HOME}/.local/share/applications/Zoom.desktop"
update-desktop-database ~/.local/share/applications
@TomConlin
Copy link

TomConlin commented Nov 16, 2021

may want to make a tiny useless rearrangement of a perfectly functional script before the
"useless uses of cat" police show up.

Loading

@zurohki
Copy link

zurohki commented Nov 16, 2021

You can even keep the order the same on the command line without the cat, to maintain the input -> processing -> output flow:

< /usr/share/applications/Zoom.desktop sed -E ...

Loading

@abraithwaite
Copy link
Author

abraithwaite commented Nov 16, 2021

🤷 What are the 🐱 👮‍♀️ going to do? Put me in 🐱 jail?

I wrote the script organically, so I started with cat Zoom.desktop to see what it did at all, then added the rest. I'm not going to retype cat -> sed if piping it is easier and accomplishes the same thing.

FWIW I do appreciate when people share alternative ways to write things in bash, but it's horrible enough already that getting something functional at all is an accomplishment for any programmer at any skill level.

Loading

@quilicicf
Copy link

quilicicf commented Nov 16, 2021

Thanks for sharing, will try it!

My alternative implementation so I can try multiple times and fine-tune the settings.

!# /usr/bin/env bash

set -xe

main() (
  allowedCpus="${1?Missing allowed CPUs, ex: 0-4}"
  maxMemory="${2?Missing max memory, ex: 6G}"
  
  # Add parameter checks to avoid invalid values here
  
  {
    printf '[Slice]\n'
    printf 'AllowedCPUs=%s\n' "${allowedCpus}"
    printf 'MemoryHigh=%s\n' "${maxMemory}"
  } > "${HOME}/.config/systemd/user/zoom.slice"
  
  awk '{ 
    if ($0 ~ /^Exec=/) 
      print "Exec=/usr/bin/systemd-run --user --slice=zoom.slice /opt/zoom/ZoomLauncher"; 
    else 
      print; 
  }' < /usr/share/applications/Zoom.desktop > "${HOME}/.local/share/applications/Zoom.desktop"
    
  update-desktop-database ~/.local/share/applications
)

main "$@"

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment