LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   xlockmore vs xscreensaver (https://www.linuxquestions.org/questions/slackware-14/xlockmore-vs-xscreensaver-4175656669/)

FlinchX 04-07-2020 02:45 PM

Quote:

Originally Posted by ttk (Post 6108851)
Yes, that's most of it. My laptop draws less power and generates less heat. Heat was less of an issue with my T530, but this new P73 runs a lot hotter, even with the CPU speed throttled.

Also, SIGSTOP'ing the browser helps stave off memory leaks. Pale Moon is a lot better about not leaking memory than Firefox, but it still happens a bit.

It makes locking my system a sort of half-way suspend, without the risks or overhead of suspend. All of the processes which would consume measurable CPU are denied CPU quanta by the kernel until SIGCONT is sent, so there's nothing going on.

This is very interesting, I've never seen something like this done before. So I have one more question. Why not SIGSTOP'ing most processes then, and only keep running those that are vital for making it possible to unlock the system later (frankly, I don't know which ones would those be)? Or is it too hard to figure in a script which processes to keep running and which ones to stop?

ttk 04-07-2020 05:04 PM

1 Attachment(s)
Quote:

Originally Posted by FlinchX (Post 6108856)
This is very interesting, I've never seen something like this done before. So I have one more question. Why not SIGSTOP'ing most processes then, and only keep running those that are vital for making it possible to unlock the system later (frankly, I don't know which ones would those be)? Or is it too hard to figure in a script which processes to keep running and which ones to stop?

When a script evolves into anything more than a sequence of simple commands, I switch up to perl :-)

The perl for implementing this would be easy. The hard part would be working up a list of processes to not stop. Once that is incorporated into a regex ($keepers), sending SIGSTOP to everything else is a one-liner:
Code:

kill 19, (map {$_ =~ /^\w+\s+(\d+)/ ? $1 : ()} grep !/$keepers/, `ps auxww`);
Or split out into simple statements for readability and using a precompiled regex:
Code:

my @stopped;  # a list of pids we are stopping, for continuing later
for my $p (`ps auxww`) { # iterates over the output of command, assigning $p to each line of output
  next if ($p =~ $keepers);  # skip processes we need, like init and Xorg
  next if ($p !~ /^\w+\s+(\d+)/);  # extract the process id with a regex
  my $pid = $1;
  push @stopped, $pid;  # save pid for later
  kill 19, $pid;  # send SIGSTOP to the process
}

And then to issue SIGCONT to the stopped processes we can just pass the whole list to kill:
Code:

kill 18, @stopped;
The $keepers regex would be something like /(\[|$$|sshd|xlock|Xorg)/ .. I'd include sshd in case I needed to ssh into the laptop while it was locked. The "$$" is perl's builtin for referring to its own process, so adding $$ to the regex would prevent the script from stopping itself. The "\[" would match the kernel processes and init (which shows the runlevel in []'s).

To stop all processes, not just those owned by the user, the script would have to run as root. If it's not, though, then the kill statement would silently fail to issue SIGSTOP to other users' processes and no harm done.

I probably won't use this logic in xlament any time soon, because it's bumping into the point of diminishing returns. When I killall that scant handful of processes, the load average sinks to about 0.01, which is good enough :-) no need to add complexity beyond that.


All times are GMT -5. The time now is 03:34 PM.