screen-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Killing backticks when bouncing screen.


From: Malte Skoruppa
Subject: Re: Killing backticks when bouncing screen.
Date: Tue, 20 Jan 2009 14:31:18 +0100
User-agent: Thunderbird 2.0.0.16 (X11/20080923)

Hi Chris,

here's a rather simple idea...

Instead of having your scripts loop infinitely, like yours do, and relying on the
mentioned behavior of the backtick command when the lifespan and autorefresh
parameters are zero (that is to say, the last line of output is always printed in the hardstatus line or captions, wherever you display your information), how about
you remove the loops in your scripts and have them output the monitoring
information only *once*?
Then, you just use the autorefresh option from screen to re-run a script after,
say, 2 seconds or whatever you feel is appropriate.

For example, instead of having a script

while [ true ]; do
# print monitoring information here
sleep 2
done

...using a 'backtick id 0 0 script.sh'...

...you would rewrite your script to:

# print monitoring information here

and use a 'backtick id 0 2 script_without_loop.sh'

In short, you move the outer loop from the script to the backtick command itself.

This results in exactly the same behavior, that is, the output is regenereated
every 2 seconds, but the script is only run once each time and terminated
directly, so no script will stay in the background, using less CPU power,
and your problem is solved.

Cheers,

Malte


Chris Jones schrieb:
I have written a few scripts that display monitoring counters on the
hardstatus line.

Thinking I would avoid the overhead of starting new processes,
particularly for stuff that requires frequent updates in order to be
relevant ..  such as CPU utilization, I thought I'd write scripts that
run in the background & iterate for ever over the following: acquire
data, format & write to stdout, sleep a while, etc.

The corresponding backtick commands in my .screenrc specify values of
zero for "lifespan" & "autorefresh" - as documented on the screen man
page:

"If both the lifespan and the autorefresh parameters are zero, the
backtick program is expected to stay in the background and generate
output once in a while.  In this case, the command is executed right
away and screen stores the last line of output.  If  a new line gets
printed screen will automatically refresh the hardstatus or the
captions."

The problem is that, if for some reason or other, I terminate the
GNU/sreen instance, the orphaned processes still run under the init
process.

As I was testing the layout of my hardstatus line the other day, I
eventually noticed--thanks to my monitoring, and the laptop's fan
kicking in :-) .. that I was using dollops of ram & cpu cycles .. well,
it turned out some 20-30 instances of my scripts and the related sleep
subprocesses were still running in the background.

Whenever I shut down a screen instance (manually terminating each
individual application), I would need to terminate those scripts as
well.. at the same time GNU/screen issues the "screen terminating"
message.

The problem is how?

Has anyone gone down this road before and found a clean solution?

Thanks,

CJ


_______________________________________________
screen-users mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/screen-users






reply via email to

[Prev in Thread] Current Thread [Next in Thread]