public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes
@ 2021-02-05  7:45 Walter Dnes
  2021-02-05  8:46 ` Andrew Udvare
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Walter Dnes @ 2021-02-05  7:45 UTC (permalink / raw
  To: Gentoo Users List

  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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-02-06 23:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-05  7:45 [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes Walter Dnes
2021-02-05  8:46 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox