On Fri, Feb 05, 2021 at 03:46:45AM -0500, Andrew Udvare wrote
> 
> > On 2021-02-05, at 02:45, Walter Dnes <waltd...@waltdnes.org> wrote:
> > 
> > done < /dev/shm/temp.txt
> 
> You don't need to write a temporary file. You can pipe this directly into the 
> while loop:
> 
> while read
> do
> ...
> done < <(ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pstop)

  I wasn't aware of the "< <" construct. Nice

> Also to avoid the second grep in Bash at least:
> 
> grep "[${1:0:1}]${1:1}"

  That causes some feedback about backgrounded processes.

  In addition to your avoiding-the-temp-file trick, I also realized that
if I read the first 3 items of each line, I can use the 2nd parameter
directly without an intermediate assignment to an array.  The latest
version of my scripts are...

======================= pstop =======================
while read userid pid rest_of_line
do
   kill -SIGSTOP ${pid}
done < <(ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pstop)

======================= pcont =======================
#!/bin/bash
while read userid pid rest_of_line
do
   kill -SIGCONT ${pid}
done < <(ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pcont)

=====================================================

  In the course of experimentation, I've made versions that killed
critical processes, requiring a reboot. {ALT}{SYSRQ} to the rescue <G>.
I'll stick with stuff that works.

-- 
Walter Dnes <waltd...@waltdnes.org>
I don't run "desktop environments"; I run useful applications

Reply via email to