Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-06 Thread Paul Colquhoun
On Saturday, February 6, 2021 6:07:39 A.M. AEDT Walter Dnes wrote:
> On Fri, Feb 05, 2021 at 06:55:12AM -0500, Rich Freeman wrote
> 
> > On Fri, Feb 5, 2021 at 2:45 AM Walter Dnes  wrote:
> > >   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.
> > 
> > man killall
> 
>   My reading of the "killall" man page is that it works on command
> names.  For my script, "pstop palemoon" stops all instances of Pale
> Moon.  But my script greps the entire line, so "pstop slashdot" will
> stop the process...
> 
> /home/waltdnes/pm/palemoon/palemoon -new-instance -p slasdot
> 
>   Does "killall" have that ability to stop a process based on any
> parameters in the command line?


Someone else mentioned pgrep. It has an associated pkill command as well.
Both appear to have a "-f" option to also search on the full command line.


-- 
Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/
  Asking for technical help in newsgroups?  Read this first:
 http://catb.org/~esr/faqs/smart-questions.html#intro






Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread Walter Dnes
On Fri, Feb 05, 2021 at 04:42:26PM -0600, Matt Connell (Gmail) wrote
> On Fri, 2021-02-05 at 13:24 -0500, Walter Dnes wrote:
> >   I'll have to take that back.  It happened again, and I was not
> > fiddling with pstop/pcont.  The common element seems to be that I was
> > compiling Pale Moon 29.0 each time it crashed.  A machine with 8 gigs of
> > ram, and 598 of 905 gigs free diskspace should not have resource issues.
> 
> I contest this claim.  8GB is pretty scant for something as large and
> complex as a modern browser.  Have you built this before on the same
> machine?

  See http://www.palemoon.org/releasenotes.shtml  My previous successful
build was 28.17.0 which was released December 18th.  Note: Chrome and
Firefox seem to bump the major release number "just because".  The Pale
Moon devs use all 3 digits.  E.g. an isolated bugfix has just been
released as 29.0.1.  When the major release number on Pale Moon is
incremented, there are big changes "under the hood", so increased
requirements are a possibility going from version 28.17 to 29.0.

There's also ongoing work on "de-unifying the sources"
https://forum.palemoon.org/viewtopic.php?f=62=24296  The thread starts
off with the question "Is it expected that Pale Moon compilation time
has almost doubled after de-unifying the sources?".  To which the head
honcho replies...

> That was only de-unifying /dom -- more will follow.
> 
> And yes, if your aren't on a particularly powerful machine with
> a fast drive, it can impact your compilation time significantly.

  I have a relatively new 16-gig machine (October) that I'll try it on.

-- 
Walter Dnes 
I don't run "desktop environments"; I run useful applications



Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread David Haller
Hello,

On Fri, 05 Feb 2021, Walter Dnes wrote:
>On Fri, Feb 05, 2021 at 06:55:12AM -0500, Rich Freeman wrote
>> On Fri, Feb 5, 2021 at 2:45 AM Walter Dnes  wrote:
>> >   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.

It's much easier to use the '-o' option of ps, i.e.:

$ ps -eo pid,cmd

That gives you a much easier format to work with. There's a lot more
fields to use, e.g. tname or tty, args or cmd, comm, and many more see
'man ps' under "STANDARD FORMAT SPECIFIERS".

>  My reading of the "killall" man page is that it works on command
>names.  For my script, "pstop palemoon" stops all instances of Pale
>Moon.  But my script greps the entire line, so "pstop slashdot" will
>stop the process...
>
>/home/waltdnes/pm/palemoon/palemoon -new-instance -p slasdot
>
>  Does "killall" have that ability to stop a process based on any
>parameters in the command line?

The following script does:

 ~/bin/pstop && ln -s pstop ~/bin/pcont 
#!/usr/bin/gawk -f
BEGINFILE { if( FILENAME != "" ) { exit(0); } }
BEGIN {
### determine if were run as pstop or pcont
cmdlinefile = "/proc/" PROCINFO["pid"] "/cmdline" ;
getline cmdline < cmdlinefile;
n = split(cmdline, argv, "\0");
IAM=argv[3];
if( IAM ~ /pstop$/) { SIG="STOP"; } else { SIG="CONT"; };

### now to work ...
printf("%s-ing pids: ", SIG); 
bcmd = sprintf("kill -%s ", SIG);
pscmd = "ps -eo pid,cmd";

# IGNORECASE=1 ### uncomment for case insensitive matching
while ( pscmd | getline ) {
if( $1 != PROCINFO["pid"] ) { ### ignore ourself
p = $1; $1 = ""; ### save pid to p; prune pid from $0
for(i=1; i < (ARGC); i++) {
if( $0 ~ ARGV[i] ) {
printf("%s ", p);
cmd = bcmd p;
system(cmd);
}
}
}
}
}
END { printf("\n"); }


Arguments can be any number of (quoted where neccessary) regular
expressions described under 'Regular Expressions' in 'man gawk'
(basically Extended POSIX REs as in egrep, see 'man 7 regex').

Example use:

$ pstop palemoon firefox slashdot 'chrom(e|ium)'

(and the same for pcont)

HTH,
-dnh

-- 
Love your enemies: they'll go crazy trying to figure out what you're up
to. -- BSD fortune file



Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread Matt Connell (Gmail)
On Fri, 2021-02-05 at 13:24 -0500, Walter Dnes wrote:
>   I'll have to take that back.  It happened again, and I was not
> fiddling with pstop/pcont.  The common element seems to be that I was
> compiling Pale Moon 29.0 each time it crashed.  A machine with 8 gigs of
> ram, and 598 of 905 gigs free diskspace should not have resource issues.

I contest this claim.  8GB is pretty scant for something as large and
complex as a modern browser.  Have you built this before on the same
machine?




Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread Walter Dnes
On Fri, Feb 05, 2021 at 02:00:05PM -0500, Walter Dnes wrote
> 
>   In the course of experimentation, I've made versions that killed
> critical processes, requiring a reboot. {ALT}{SYSRQ} to the rescue .
> I'll stick with stuff that works.

  I'll have to take that back.  It happened again, and I was not
fiddling with pstop/pcont.  The common element seems to be that I was
compiling Pale Moon 29.0 each time it crashed.  A machine with 8 gigs of
ram, and 598 of 905 gigs free diskspace should not have resource issues.

-- 
Walter Dnes 
I don't run "desktop environments"; I run useful applications



Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread Neil Bothwick
On Fri, 5 Feb 2021 14:07:39 -0500, Walter Dnes wrote:

> > man killall  
> 
>   My reading of the "killall" man page is that it works on command
> names.  For my script, "pstop palemoon" stops all instances of Pale
> Moon.  But my script greps the entire line, so "pstop slashdot" will
> stop the process...
> 
> /home/waltdnes/pm/palemoon/palemoon -new-instance -p slasdot
> 
>   Does "killall" have that ability to stop a process based on any
> parameters in the command line?

No, but you could look at using pgrep to avoid some of the awkery.


-- 
Neil Bothwick

Velilind's Laws of Experimentation:
1. If reproducibility may be a problem, conduct the test only once.
2. If a straight line fit is required, obtain only two data points.


pgpjRh3VFJSr4.pgp
Description: OpenPGP digital signature


Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread Rich Freeman
On Fri, Feb 5, 2021 at 2:07 PM Walter Dnes  wrote:
>
> On Fri, Feb 05, 2021 at 06:55:12AM -0500, Rich Freeman wrote
> > On Fri, Feb 5, 2021 at 2:45 AM Walter Dnes  wrote:
> > >
> > >   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.
> >
> > man killall
>
>   My reading of the "killall" man page is that it works on command
> names.  For my script, "pstop palemoon" stops all instances of Pale
> Moon.  But my script greps the entire line, so "pstop slashdot" will
> stop the process...

Yeah, that is fair enough.  If you want to use other elements of the
command line/etc then you'd need to do something more along the lines
of your script.  Just wanted to make people aware.

-- 
Rich



Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread Walter Dnes
On Fri, Feb 05, 2021 at 06:55:12AM -0500, Rich Freeman wrote
> On Fri, Feb 5, 2021 at 2:45 AM Walter Dnes  wrote:
> >
> >   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.
> 
> man killall

  My reading of the "killall" man page is that it works on command
names.  For my script, "pstop palemoon" stops all instances of Pale
Moon.  But my script greps the entire line, so "pstop slashdot" will
stop the process...

/home/waltdnes/pm/palemoon/palemoon -new-instance -p slasdot

  Does "killall" have that ability to stop a process based on any
parameters in the command line?

-- 
Walter Dnes 
I don't run "desktop environments"; I run useful applications



Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread Walter Dnes
On Fri, Feb 05, 2021 at 03:46:45AM -0500, Andrew Udvare wrote
> 
> > On 2021-02-05, at 02:45, Walter Dnes  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 .
I'll stick with stuff that works.

-- 
Walter Dnes 
I don't run "desktop environments"; I run useful applications



Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread Ramon Fischer

Awesome stuff!

It might be unrelated, but I would like to mention a script[1] here, 
which I have written in Bash to analyse process signals. It is called 
"psig", which mimics some of the behaviour of Solaris' "psig" binary:


   $ psig 23024

   PID: 23024
   Name: chrome
   Queued: 0/63858
   Signals caught:
   ---
   Signal 17: SIGCHLD
   Signal 15: SIGTERM
   Signal 2: SIGINT
   Signal 1: SIGHUP
   Hexadecimal:  0 0 0 0 0 0 0 1 8
   0 0 1 4 0 0 3
   Binary:                0001  1000 
       0001  0100      0011

   Signals pending (process):
   --
   No signals found.

   Signals pending (thread):
   -
   No signals found.

   Signals blocked:
   
   No signals found.

   Signals ignored:
   
   Signal 13: SIGPIPE
   Hexadecimal:  0 0 0 0 0 0 0 0 0
   0 0 0 1 0 0 0
   Binary:                   
         0001      

-Ramon

[1] https://github.com/keks24/psig


On 05/02/2021 08:45, Walter Dnes wrote:

   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.



--
GPG public key: 5983 98DA 5F4D A464 38FD CF87 155B E264 13E6 99BF




OpenPGP_signature
Description: OpenPGP digital signature


Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread Rich Freeman
On Fri, Feb 5, 2021 at 2:45 AM Walter Dnes  wrote:
>
>   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.

man killall


-- 
Rich



Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-05 Thread Andrew Udvare


> On 2021-02-05, at 02:45, Walter Dnes  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)

Also to avoid the second grep in Bash at least:

grep "[${1:0:1}]${1:1}"

 $ ps -ef | grep '[l]vmetad'
root 965   1  0 Jan31 ?00:00:00 /sbin/lvmetad -f

^ No grep in output.

--
Andrew


[gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes

2021-02-04 Thread Walter Dnes
  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 
I don't run "desktop environments"; I run useful applications