Re: run binary executable with . in bash?
From: John Kelly (jak_at_sevenkings.net)
Date: 09/20/04
- Next message: D. Alvarado: "Summing file size"
- Previous message: Paul Jarc: "Re: run binary executable with . in bash?"
- In reply to: William Park: "Re: run binary executable with . in bash?"
- Next in thread: William Park: "Re: run binary executable with . in bash?"
- Reply: William Park: "Re: run binary executable with . in bash?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 20 Sep 2004 20:12:16 GMT
On 20 Sep 2004 18:38:20 GMT, William Park <opengeometry@yahoo.ca>
wrote:
>Could you not have 2 independent loops,
> - one appending to /.../access, and
> - another calling 'newmailfiles' every 7s
>?
>
>For example,
>
> while sleep 7; do
> newmailfiles
> done &
>
> while read -u 3; do
> echo ... >> /root/local/sendmail/etc.mail/access
> echo ...
> done
You could, but then you wake up every 7 seconds, even if there is no
work to do. And worse yet, you have a race condition where your batch
process may execute when the read loop is still writing to the files
and they are in an incomplete state. My example only shows one file,
but I need a general solution for use in other applications, where I
may write to multiple files.
By blocking on the read and trapping a signal, I sleep indefinitely,
until there is at least one input in the batch, and then wait a short
interval of 7 seconds to see if there might be a burst of input.
That way, I don't repeat the entire batch process separately for each
input (it may be a lengthy process), and the first input opening a new
batch does not wait very long to be processed.
If there is a huge burst of input and the 7 second cutoff starts the
batch process while there is still more input to read, that is not a
problem. Any input not included in the current batch will just stack
up in the FIFO, and when the batch process completes, the read loop
will churn thru the input quickly on the next cycle, including them
all in the next batch, which will be delayed no more than 7 seconds.
And I have no race conditions.
- Next message: D. Alvarado: "Summing file size"
- Previous message: Paul Jarc: "Re: run binary executable with . in bash?"
- In reply to: William Park: "Re: run binary executable with . in bash?"
- Next in thread: William Park: "Re: run binary executable with . in bash?"
- Reply: William Park: "Re: run binary executable with . in bash?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|