[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Command hangs when using process substitution
From: |
Greg Wooledge |
Subject: |
Re: Command hangs when using process substitution |
Date: |
Sat, 18 Nov 2023 09:43:49 -0500 |
On Sat, Nov 18, 2023 at 08:36:06AM -0500, dbarrett--- via Bug reports for the
GNU Bourne Again SHell wrote:
> echo foo | tee >(xclip -i) | tr o x
>
> The command does print "fxx" but then it hangs.
>
> The same command behaves correctly when run in zsh.
For the record, here's what processes are running on the terminal while
it's in the "hanging" state:
unicorn:~$ ps f -ft pts/28
UID PID PPID C STIME TTY STAT TIME CMD
greg 1082506 1082504 0 09:21 pts/28 Ss 0:00 bash
greg 1082862 1082506 0 09:35 pts/28 S+ 0:00 \_ tr o x
greg 1082864 1 0 09:35 pts/28 S+ 0:00 xclip -i
The tee process has exited, but somehow the tr process has not --
which must mean that tr's stdin is still open.
One additional observation: if I highlight something (e.g. that ps
output), this causes the pipeline to terminate. I assume the xclip
process somehow notices the highlighting and exits, which causes
tr to exit, because (presumably) it's the orphaned xclip process
whose output was still connected to tr's input.
Without copy/pasting anything, it'll be a bit annoying to diagnose, but
let's try:
unicorn:~$ ps f -ft pts/28
UID PID PPID C STIME TTY STAT TIME CMD
greg 1082506 1082504 0 09:21 pts/28 Ss 0:00 bash
greg 1082907 1082506 0 09:39 pts/28 S+ 0:00 \_ tr o x
greg 1082909 1 0 09:39 pts/28 S+ 0:00 xclip -i
unicorn:~$ ls -l /proc/1082907/fd
total 0
lr-x------ 1 greg greg 64 Nov 18 09:39 0 -> 'pipe:[29847034]'
lrwx------ 1 greg greg 64 Nov 18 09:39 1 -> /dev/pts/28
lrwx------ 1 greg greg 64 Nov 18 09:39 2 -> /dev/pts/28
unicorn:~$ ls -l /proc/1082909/fd
total 0
lr-x------ 1 greg greg 64 Nov 18 09:39 0 -> 'pipe:[29848673]'
l-wx------ 1 greg greg 64 Nov 18 09:39 1 -> 'pipe:[29847034]'
lrwx------ 1 greg greg 64 Nov 18 09:39 2 -> /dev/pts/28
lrwx------ 1 greg greg 64 Nov 18 09:39 3 -> 'socket:[29847035]'
In this run, I can confirm that the stdout of xclip is indeed attached
to the stdin of tr, via pipe:[29847034]. Therefore, as a workaround,
I would suggest:
unicorn:~$ echo foo | tee >(xclip -i >/dev/null) | tr o x
fxx
unicorn:~$
That should work as desired, in whichever shell you're using that
has process substitutions.