zsh-users
 help / color / mirror / code / Atom feed
From: Lewis Butler <lbutler@covisp.net>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: infinite loop that is possible to quit
Date: Tue, 1 Dec 2020 02:53:00 -0700	[thread overview]
Message-ID: <360E0D44-A1C0-4D68-A2B4-4B017F2EB277@covisp.net> (raw)
In-Reply-To: <875z5m9twt.fsf@zoho.eu>

On 30 Nov 2020, at 18:50, Emanuel Berg <moasenwood@zoho.eu> wrote:
> while true; do
>  # run program
>  sleep 1
> done

Since I tend to use loops like this just to do simple things like check status on some other process, that is the method I mostly use (though usually with a sleep 5 or 30 or 300, very rarely a sleep 1). When you get to more complicated scripts though, it is better to have some brains in the script for terminating cleanly.

How you do that depends very much on what you are doing.

I like grail@goldweb.com.au's example of trapping TERM QUIT and HUP, but that is not always the best solution either.

For example, I used to have a pair of scripts. One checked that a network mount was enabled and if it vanished, it remounted it, and restarted the second script. The other synced files to the network mount. When the second script was done, it wrote a file to the network with the output of the sync (how many files, how much data was transferred). When the first script saw that file, it exited.

This was necessary when I had a somewhat unreliable network connection to the remote server. Or at least it was the simplest way I had at the time to ensure that the network sync happened as quickly as possible and that I didn't end up with an incomplete sync because the network had gone offline for 40 seconds at 03:19.

Basically, when you have an infinite loop, you have to have an idea of what is going to end that loop, and what makes sense depends on what the loop is doing. It may be a file, or a time, or user intervention, or a particular condition on the machine. All are valid, and which is best depends on what you're trying to achieve.

-- 
ɹןʇnqן
<mailto:lbutler@covisp.net>
tel:+1.303.219.0564





  parent reply	other threads:[~2020-12-01  9:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01  1:50 Emanuel Berg
2020-12-01  7:36 ` Alex Satrapa
2020-12-01  9:53 ` Lewis Butler [this message]
2020-12-01 17:17 ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=360E0D44-A1C0-4D68-A2B4-4B017F2EB277@covisp.net \
    --to=lbutler@covisp.net \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).