Gentoo Archives: gentoo-user

From: Walter Dnes <waltdnes@××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes
Date: Fri, 05 Feb 2021 14:00:13
Message-Id: YB2VtcldZZoufsOq@waltdnes.org
In Reply to: Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes by Andrew Udvare
1 On Fri, Feb 05, 2021 at 03:46:45AM -0500, Andrew Udvare wrote
2 >
3 > > On 2021-02-05, at 02:45, Walter Dnes <waltdnes@××××××××.org> wrote:
4 > >
5 > > done < /dev/shm/temp.txt
6 >
7 > You don't need to write a temporary file. You can pipe this directly into the while loop:
8 >
9 > while read
10 > do
11 > ...
12 > done < <(ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pstop)
13
14 I wasn't aware of the "< <" construct. Nice
15
16 > Also to avoid the second grep in Bash at least:
17 >
18 > grep "[${1:0:1}]${1:1}"
19
20 That causes some feedback about backgrounded processes.
21
22 In addition to your avoiding-the-temp-file trick, I also realized that
23 if I read the first 3 items of each line, I can use the 2nd parameter
24 directly without an intermediate assignment to an array. The latest
25 version of my scripts are...
26
27 ======================= pstop =======================
28 while read userid pid rest_of_line
29 do
30 kill -SIGSTOP ${pid}
31 done < <(ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pstop)
32
33 ======================= pcont =======================
34 #!/bin/bash
35 while read userid pid rest_of_line
36 do
37 kill -SIGCONT ${pid}
38 done < <(ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pcont)
39
40 =====================================================
41
42 In the course of experimentation, I've made versions that killed
43 critical processes, requiring a reboot. {ALT}{SYSRQ} to the rescue <G>.
44 I'll stick with stuff that works.
45
46 --
47 Walter Dnes <waltdnes@××××××××.org>
48 I don't run "desktop environments"; I run useful applications

Replies

Subject Author
Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes Walter Dnes <waltdnes@××××××××.org>