help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Michaël Cadilhac" <michael@cadilhac.name>
Cc: zsh-workers@zsh.org
Subject: Re: Unexpected infinite loop with xclip
Date: Wed, 7 Sep 2022 15:20:51 -0700	[thread overview]
Message-ID: <CAH+w=7bNRWy-N8WkMPgKUwRnAdh8T5_eGnM+9ZTXvQWuhde4Uw@mail.gmail.com> (raw)
In-Reply-To: <CADt3fpMftOpCc-6dkMYDCpJg_d9Th4vnvaUJHZbUA4nqx-3PVQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 898 bytes --]

On Wed, Sep 7, 2022 at 2:44 PM Michaël Cadilhac <michael@cadilhac.name>

> $ while :; do read; echo | xclip; echo loop; done

Bash executes the left side of a pipeline in the current shell and the
right side in a forked subshell.  Zsh does the opposite, which means xclip
is a process group leader with access to the terminal.

xclip itself then forks and clones a copy which continues running.  That
copy has control of the terminal, which causes "read" to see an I/O error
and immediately fail.  You can see read exiting failure if you change the
loop to be
    while :; do read; echo $?; echo | xclip; echo loop; done

You're not testing the return value of read, so the shell goes on to the
next statement and the effect repeats.  Each new xclip causes the previous
xclip to exit (cf. xclip -l option) by grabbing the selection, so you never
run out of processes.

[-- Attachment #2: Type: text/html, Size: 1252 bytes --]

      reply	other threads:[~2022-09-07 22:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-07 21:44 Michaël Cadilhac
2022-09-07 22:20 ` Bart Schaefer [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:

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

  git send-email \
    --in-reply-to='CAH+w=7bNRWy-N8WkMPgKUwRnAdh8T5_eGnM+9ZTXvQWuhde4Uw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=michael@cadilhac.name \
    --cc=zsh-workers@zsh.org \


* 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


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).