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: Chris Jones
Subject: Re: Killing backticks when bouncing screen.
Date: Fri, 23 Jan 2009 19:55:47 -0500
User-agent: Mutt/1.5.13 (2006-08-11)

On Fri, Jan 23, 2009 at 11:11:45AM EST, Gerhard Siegesmund wrote:
> Hello CJ
> 
> I, for example, use the following script to monitor the number of
> messages on my mailbox:
> 
> ------------------------------------------------------------------------
> #!/bin/sh
> 
> FETCHMAIL='/usr/bin/fetchmail'
> 
> while true; do
>   $FETCHMAIL -c | sed -e 's/.* \([0-9]*\) messages* (\([0-9]*\) seen.*/\1 - 
> \2/g' | bc || exit 1
>   sleep 60
> done
> ------------------------------------------------------------------------
> 
> 
> I had the same problem as you. What fixed the problem was the '|| exit
> 1'-Statement.
> 
> The point is, when the terminal where the script writes to doesn't exist
> anymore, then the outputting tool should signal this with an exitcode
> other than 0. With '|| exit 1' in my example I check whether bc was able
> to correctly output its result. If that was not possible, end the script
> with 'exit 1'.

As I understand it correctly, it could still be "exit 0", right? What
matters is the non-zero exit code from the pipe? Or does init need to be
told that the child process ended with an ec^=0? Or even with precisely
ec=1?

> This way everytime my screen instance is killed, all the running
> backtick-Scripts also end.

Brilliant! 

And this just goes to show that understanding terminals is the first
requirement of *nix programming.

> Hope this helps.

So much so that.. I'll forgive you for top-posting.

;-)

Really, what a clever solution!!!

As to others who replied, please don't fell slighted in any way. Your
comments were also very useful:

They made me realize that one other thing that doesn't make sense about
my scripts is the "sleep" command.  Maybe "sleep 60" or "sleep 1200"
don't matter all that much - but having the linux kernel create a new
address space every second just because I want my little script to go to
sleep for one second.. and then a second later go through the motions of
terminating a process that should not have been started in the first
place.. sounds like a major waste of resources. Is there any way I could
replace this by a system call or its library wrapper ..  After all, what
I really want is to tell the kernel not to dispatch my process for the
next second or so.  Why go about it in such a roundabout way by creating
an empty subprocess that does nothing for one second?

I'm no programmer.. so I hope the above makes sense.

Humble as they are, these are monitoring tools .. I do want their impact
on the system to be as neglibible as possible.

Thanks,

CJ




reply via email to

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