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 <[email protected]>
I don't run "desktop environments"; I run useful applications