From: "Walter Dnes" <waltdnes@waltdnes.org>
To: Gentoo Users List <gentoo-user@lists.gentoo.org>
Subject: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes
Date: Fri, 5 Feb 2021 02:45:33 -0500 [thread overview]
Message-ID: <YBz3nb67JhsfkEfx@waltdnes.org> (raw)
Thanks for all the help over the years fellow Gentoo'ers. Maybe I can
return the favour. So you've got a bunch of programs like Gnumeric or
QEMU or Pale Moon ( or Firefox or Chrome or Opera ) sessions open, that
are chewing up cpu and ram. You need those resouces for another
program, but you don't want to shut those programs down and lose your
place. If the programs could be frozen, cpu usage would go away, and
memory could be swapped out. Here's a real-life example subset of a
"ps -ef" output on my system. Replace "palemoon" with "firefox" or
"chrome" or whatever browser you're using.
waltdnes 4025 3173 0 Jan20 ? 01:54:21 /home/waltdnes/pm/palemoon/palemoon -new-instance -p palemoon
waltdnes 7580 3173 4 Jan21 ? 17:45:11 /home/waltdnes/pm/palemoon/palemoon -new-instance -p dslr
waltdnes 9813 3173 4 Jan21 ? 16:24:23 /home/waltdnes/pm/palemoon/palemoon -new-instance -p wxforum
waltdnes 22455 3173 58 01:31 ? 00:08:29 /home/waltdnes/pm/palemoon/palemoon -new-instance -p slashdot
waltdnes 22523 3173 0 01:31 ? 00:00:05 /home/waltdnes/pm/palemoon/palemoon -new-instance -p youtube
waltdnes 22660 3173 12 01:45 ? 00:00:04 /usr/bin/gnumeric /home/waltdnes/worldtemps/temperatures/temperatures.gnumeric
waltdnes 20346 20345 4 Jan28 ? 08:10:50 /usr/bin/qemu-system-x86_64 -enable-kvm -runas waltdnes -cpu host -monitor vc -display gtk -drive file=arcac.img,format=raw -netdev user,id=mynetwork -device e1000,netdev=mynetwork -rtc base=localtime,clock=host -m 1024 -name ArcaOS VM -vga std -parallel none
You might want to RTFM on the "kill" command if you're skeptical. It
does a lot more than kill programs. "kill -L" will give you a nicely
formatted list of available signals. For this discussion we're
interested in just "SIGCONT" and "SIGSTOP" ( *NOT* "SIGSTP" ). If I
want to freeze the Slashdot session, I can run "kill -SIGSTOP 22455". To
unfreeze it, I can run "kill -SIGCONT 22455". You can "SIGSTOP" on a
pid multiple times consecutively without problems; ditto for "SIGCONT".
So far, so good, but running "ps -ef | grep whatever" and then
typing the kill -SIGSTOP/SIGCONT command on the correct pid is grunt
work, subject to typos. I've set up a couple of scripts in ~/bin to
stop/continue processes, or groups thereof. The following scripts do a
"dumb grep" of "ps -ef" output, redirecting to /dev/shm/temp.txt. That
file is then read, and the second element of each line is the pid, which
is fed to the "kill" command. I store the scripts as ~/bin/pstop and
~/bin/pcont.
================== pstop (process stop) script ==================
#!/bin/bash
ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pstop > /dev/shm/temp.txt
while read
do
inputarray=(${REPLY})
kill -SIGSTOP ${inputarray[1]}
done < /dev/shm/temp.txt
================ pcont (process continue) script ================
#!/bin/bash
ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pcont > /dev/shm/temp.txt
while read
do
inputarray=(${REPLY})
kill -SIGCONT ${inputarray[1]}
done < /dev/shm/temp.txt
=================================================================
To stop all Pale Moon instances, execute "pstop palemoon". To stop
only the Slashdot session, run "pstop slashdot". Ditto for the pcont
command. I hope people find this useful.
--
Walter Dnes <waltdnes@waltdnes.org>
I don't run "desktop environments"; I run useful applications
next reply other threads:[~2021-02-05 7:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-05 7:45 Walter Dnes [this message]
2021-02-05 8:46 ` [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes Andrew Udvare
2021-02-05 19:00 ` Walter Dnes
2021-02-05 18:24 ` Walter Dnes
2021-02-05 22:42 ` Matt Connell (Gmail)
2021-02-06 7:54 ` Walter Dnes
2021-02-05 11:55 ` Rich Freeman
2021-02-05 19:07 ` Walter Dnes
2021-02-05 14:39 ` Rich Freeman
2021-02-05 16:23 ` Neil Bothwick
2021-02-06 1:08 ` David Haller
2021-02-06 4:46 ` Paul Colquhoun
2021-02-05 12:12 ` Ramon Fischer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YBz3nb67JhsfkEfx@waltdnes.org \
--to=waltdnes@waltdnes.org \
--cc=gentoo-user@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox