zsh-users
 help / color / mirror / code / Atom feed
From: dana <dana@dana.is>
To: TJ Luoma <luomat@gmail.com>
Cc: Zsh MailingList <zsh-users@zsh.org>
Subject: Re: is '&' the right way to do this?
Date: Tue, 17 Dec 2019 22:38:13 -0600	[thread overview]
Message-ID: <CBDDDFAC-7244-42BE-A80F-93910AE2139C@dana.is> (raw)
In-Reply-To: <CADjGqHsi7uGmSfXaty8bWo9j4+Daa5tdEzvv2qKAgnMjNcowKg@mail.gmail.com>

On 17 Dec 2019, at 06:33, TJ Luoma <luomat@gmail.com> wrote:
> ( find / -type f -print > /tmp/filelist.txt ) &

Technically you don't need the parentheses in this example

On 17 Dec 2019, at 06:33, TJ Luoma <luomat@gmail.com> wrote:
> Question #1:  Would it be better for any reason to use `&|` such as:
> or is the use of `&|` really only beneficial for interactive shells?

When the MONITOR and HUP options are both enabled, the shell will
automatically send SIGHUP to all jobs in the job-control table when it shuts
down (which usually kills their processes). Disowning a background job with
&|, &!, or disown removes it from the job-control table, which prevents it
from receiving the signal

Since MONITOR is only enabled by default in interactive shells, the main
benefit of disowning doesn't usually apply in scripts. However, it doesn't
hurt anything either, and it may be useful in rare cases, e.g., where you
specifically want to exclude certain jobs from the job-control table

On 17 Dec 2019, at 06:33, TJ Luoma <luomat@gmail.com> wrote:
> Question #2: Are there better ways of doing this?

There are other options that you might use in some scenarios, like coproc and
nohup and setsid and even systemd, but & is probably fine for the general use
case of 'run a job asynchronously / in the background'. I think so, anyway

dana


      reply	other threads:[~2019-12-18  4:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-17 12:33 TJ Luoma
2019-12-18  4:38 ` dana [this message]

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=CBDDDFAC-7244-42BE-A80F-93910AE2139C@dana.is \
    --to=dana@dana.is \
    --cc=luomat@gmail.com \
    --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).