Skip to content

Instantly share code, notes, and snippets.

@bja2142
bja2142 / gist:e60cb46b358d74c4801d5ae05fa76c07
Created August 17, 2022 21:37
Kill all users who are using more than a fixed limit of process on Linux
MAX_PROCESS_LIMIT=10
systemctl status user.slice |
egrep "user-[0-9]+\.slice" |
sed 's/.*user-\([0-9]*\).*/\1/' | # get uid
while read uid; do
test $uid -ne 0 && ( # ignore root
tasks=$(
systemctl status user-${uid}.slice |
grep -e Tasks 2>&1 |
sed 's/\w*Tasks: \([1-9][0-9]*\) (limit: [0-9]*)/\1/'