Gentoo Archives: gentoo-user

From: Ramon Fischer <Ramon_Fischer@×××××××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes
Date: Fri, 05 Feb 2021 12:12:55
Message-Id: AM6PR10MB24402183EE63CB64EC79C578EFB29@AM6PR10MB2440.EURPRD10.PROD.OUTLOOK.COM
In Reply to: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes by Walter Dnes
1 Awesome stuff!
2
3 It might be unrelated, but I would like to mention a script[1] here,
4 which I have written in Bash to analyse process signals. It is called
5 "psig", which mimics some of the behaviour of Solaris' "psig" binary:
6
7 $ psig 23024
8
9 PID: 23024
10 Name: chrome
11 Queued: 0/63858
12 Signals caught:
13 ---------------
14 Signal 17: SIGCHLD
15 Signal 15: SIGTERM
16 Signal 2: SIGINT
17 Signal 1: SIGHUP
18 Hexadecimal:  0     0     0     0     0     0 0     1     8    
19 0     0     1     4     0     0     3
20 Binary:       0000  0000  0000  0000  0000  0000 0000  0001  1000 
21 0000  0000  0001  0100  0000  0000  0011
22
23 Signals pending (process):
24 --------------------------
25 No signals found.
26
27 Signals pending (thread):
28 -------------------------
29 No signals found.
30
31 Signals blocked:
32 ----------------
33 No signals found.
34
35 Signals ignored:
36 ----------------
37 Signal 13: SIGPIPE
38 Hexadecimal:  0     0     0     0     0     0 0     0     0    
39 0     0     0     1     0     0     0
40 Binary:       0000  0000  0000  0000  0000  0000 0000  0000  0000 
41 0000  0000  0000  0001  0000  0000  0000
42
43 -Ramon
44
45 [1] https://github.com/keks24/psig
46
47
48 On 05/02/2021 08:45, Walter Dnes wrote:
49 > Thanks for all the help over the years fellow Gentoo'ers. Maybe I can
50 > return the favour. So you've got a bunch of programs like Gnumeric or
51 > QEMU or Pale Moon ( or Firefox or Chrome or Opera ) sessions open, that
52 > are chewing up cpu and ram. You need those resouces for another
53 > program, but you don't want to shut those programs down and lose your
54 > place. If the programs could be frozen, cpu usage would go away, and
55 > memory could be swapped out. Here's a real-life example subset of a
56 > "ps -ef" output on my system. Replace "palemoon" with "firefox" or
57 > "chrome" or whatever browser you're using.
58 >
59 > waltdnes 4025 3173 0 Jan20 ? 01:54:21 /home/waltdnes/pm/palemoon/palemoon -new-instance -p palemoon
60 > waltdnes 7580 3173 4 Jan21 ? 17:45:11 /home/waltdnes/pm/palemoon/palemoon -new-instance -p dslr
61 > waltdnes 9813 3173 4 Jan21 ? 16:24:23 /home/waltdnes/pm/palemoon/palemoon -new-instance -p wxforum
62 > waltdnes 22455 3173 58 01:31 ? 00:08:29 /home/waltdnes/pm/palemoon/palemoon -new-instance -p slashdot
63 > waltdnes 22523 3173 0 01:31 ? 00:00:05 /home/waltdnes/pm/palemoon/palemoon -new-instance -p youtube
64 > waltdnes 22660 3173 12 01:45 ? 00:00:04 /usr/bin/gnumeric /home/waltdnes/worldtemps/temperatures/temperatures.gnumeric
65 > 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
66 >
67 > You might want to RTFM on the "kill" command if you're skeptical. It
68 > does a lot more than kill programs. "kill -L" will give you a nicely
69 > formatted list of available signals. For this discussion we're
70 > interested in just "SIGCONT" and "SIGSTOP" ( *NOT* "SIGSTP" ). If I
71 > want to freeze the Slashdot session, I can run "kill -SIGSTOP 22455". To
72 > unfreeze it, I can run "kill -SIGCONT 22455". You can "SIGSTOP" on a
73 > pid multiple times consecutively without problems; ditto for "SIGCONT".
74 >
75 > So far, so good, but running "ps -ef | grep whatever" and then
76 > typing the kill -SIGSTOP/SIGCONT command on the correct pid is grunt
77 > work, subject to typos. I've set up a couple of scripts in ~/bin to
78 > stop/continue processes, or groups thereof. The following scripts do a
79 > "dumb grep" of "ps -ef" output, redirecting to /dev/shm/temp.txt. That
80 > file is then read, and the second element of each line is the pid, which
81 > is fed to the "kill" command. I store the scripts as ~/bin/pstop and
82 > ~/bin/pcont.
83 >
84 > ================== pstop (process stop) script ==================
85 > #!/bin/bash
86 > ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pstop > /dev/shm/temp.txt
87 > while read
88 > do
89 > inputarray=(${REPLY})
90 > kill -SIGSTOP ${inputarray[1]}
91 > done < /dev/shm/temp.txt
92 >
93 > ================ pcont (process continue) script ================
94 > #!/bin/bash
95 > ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pcont > /dev/shm/temp.txt
96 > while read
97 > do
98 > inputarray=(${REPLY})
99 > kill -SIGCONT ${inputarray[1]}
100 > done < /dev/shm/temp.txt
101 >
102 > =================================================================
103 >
104 > To stop all Pale Moon instances, execute "pstop palemoon". To stop
105 > only the Slashdot session, run "pstop slashdot". Ditto for the pcont
106 > command. I hope people find this useful.
107 >
108
109 --
110 GPG public key: 5983 98DA 5F4D A464 38FD CF87 155B E264 13E6 99BF

Attachments

File name MIME type
OpenPGP_signature.asc application/pgp-signature