1 |
Thanks for all the help over the years fellow Gentoo'ers. Maybe I can |
2 |
return the favour. So you've got a bunch of programs like Gnumeric or |
3 |
QEMU or Pale Moon ( or Firefox or Chrome or Opera ) sessions open, that |
4 |
are chewing up cpu and ram. You need those resouces for another |
5 |
program, but you don't want to shut those programs down and lose your |
6 |
place. If the programs could be frozen, cpu usage would go away, and |
7 |
memory could be swapped out. Here's a real-life example subset of a |
8 |
"ps -ef" output on my system. Replace "palemoon" with "firefox" or |
9 |
"chrome" or whatever browser you're using. |
10 |
|
11 |
waltdnes 4025 3173 0 Jan20 ? 01:54:21 /home/waltdnes/pm/palemoon/palemoon -new-instance -p palemoon |
12 |
waltdnes 7580 3173 4 Jan21 ? 17:45:11 /home/waltdnes/pm/palemoon/palemoon -new-instance -p dslr |
13 |
waltdnes 9813 3173 4 Jan21 ? 16:24:23 /home/waltdnes/pm/palemoon/palemoon -new-instance -p wxforum |
14 |
waltdnes 22455 3173 58 01:31 ? 00:08:29 /home/waltdnes/pm/palemoon/palemoon -new-instance -p slashdot |
15 |
waltdnes 22523 3173 0 01:31 ? 00:00:05 /home/waltdnes/pm/palemoon/palemoon -new-instance -p youtube |
16 |
waltdnes 22660 3173 12 01:45 ? 00:00:04 /usr/bin/gnumeric /home/waltdnes/worldtemps/temperatures/temperatures.gnumeric |
17 |
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 |
18 |
|
19 |
You might want to RTFM on the "kill" command if you're skeptical. It |
20 |
does a lot more than kill programs. "kill -L" will give you a nicely |
21 |
formatted list of available signals. For this discussion we're |
22 |
interested in just "SIGCONT" and "SIGSTOP" ( *NOT* "SIGSTP" ). If I |
23 |
want to freeze the Slashdot session, I can run "kill -SIGSTOP 22455". To |
24 |
unfreeze it, I can run "kill -SIGCONT 22455". You can "SIGSTOP" on a |
25 |
pid multiple times consecutively without problems; ditto for "SIGCONT". |
26 |
|
27 |
So far, so good, but running "ps -ef | grep whatever" and then |
28 |
typing the kill -SIGSTOP/SIGCONT command on the correct pid is grunt |
29 |
work, subject to typos. I've set up a couple of scripts in ~/bin to |
30 |
stop/continue processes, or groups thereof. The following scripts do a |
31 |
"dumb grep" of "ps -ef" output, redirecting to /dev/shm/temp.txt. That |
32 |
file is then read, and the second element of each line is the pid, which |
33 |
is fed to the "kill" command. I store the scripts as ~/bin/pstop and |
34 |
~/bin/pcont. |
35 |
|
36 |
================== pstop (process stop) script ================== |
37 |
#!/bin/bash |
38 |
ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pstop > /dev/shm/temp.txt |
39 |
while read |
40 |
do |
41 |
inputarray=(${REPLY}) |
42 |
kill -SIGSTOP ${inputarray[1]} |
43 |
done < /dev/shm/temp.txt |
44 |
|
45 |
================ pcont (process continue) script ================ |
46 |
#!/bin/bash |
47 |
ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pcont > /dev/shm/temp.txt |
48 |
while read |
49 |
do |
50 |
inputarray=(${REPLY}) |
51 |
kill -SIGCONT ${inputarray[1]} |
52 |
done < /dev/shm/temp.txt |
53 |
|
54 |
================================================================= |
55 |
|
56 |
To stop all Pale Moon instances, execute "pstop palemoon". To stop |
57 |
only the Slashdot session, run "pstop slashdot". Ditto for the pcont |
58 |
command. I hope people find this useful. |
59 |
|
60 |
-- |
61 |
Walter Dnes <waltdnes@××××××××.org> |
62 |
I don't run "desktop environments"; I run useful applications |