Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Unexpected infinite loop with xclip



On Wed, Sep 7, 2022 at 2:44 PM Michaël Cadilhac <michael@xxxxxxxxxxxxx> wrote:
$ 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.



Messages sorted by: Reverse Date, Date, Thread, Author