bug in bash
Hi, I found a bug when i tried with syntax <(cmd). this is an example cat <(wc -l) < bk You can follow this command, then you have bugs. I think because you created a fork getting inside in the parenthesis and the main process do < bk. They work parallel. Because of that, yeah. At least, I tried this here on this campus, at 42Heilbronn - Germany. How to fix it? It doesn't last that long. After a while, it will show "wc: stdin: read: Input/output error". Or we can ctrl C. Version 5.2 Kind regards Quoc Tri do
Re: bug in bash
On Sun, May 12, 2024 at 03:55:21AM +0200, Quốc Trị Đỗ wrote: > Hi, > > I found a bug when i tried with syntax <(cmd). this is an example > cat <(wc -l) < bk > > You can follow this command, then you have bugs. I think because you > created a fork getting inside in the parenthesis and the main process do < > bk. They work parallel. Because of that, yeah. > At least, I tried this here on this campus, at 42Heilbronn - Germany. > > How to fix it? It doesn't last that long. After a while, it will show "wc: > stdin: read: Input/output error". Or we can ctrl C. > Version 5.2 > > Kind regards > Quoc Tri do What was it that you intended to do when you composed that command? -- Andreas (Kusalananda) Kähäri Uppsala, Sweden .
Re: bug in bash
On Sun, 12 May 2024 03:55:21 +0200 Quốc Trị Đỗ wrote: > Hi, > > I found a bug when i tried with syntax <(cmd). this is an example > cat <(wc -l) < bk > > You can follow this command, then you have bugs. I think because you > created a fork getting inside in the parenthesis and the main process do < > bk. They work parallel. Because of that, yeah. > At least, I tried this here on this campus, at 42Heilbronn - Germany. > Let's replace wc with ps for a moment. $ cat <(ps -j) PIDPGID SID TTY TIME CMD 784078407840 pts/000:00:00 bash 849278407840 pts/000:00:00 ps 849384937840 pts/000:00:00 cat There, cat ends up being the sole member of the foreground process group (whose PGID happened to be 8493 at the time). It can be seen that ps is not a member of that same process group. Were ps to try to read from the standard input - as wc does - it would also fail. The reason is that only processes belonging to the foreground process group are allowed to read from the controlling terminal. > How to fix it? It doesn't last that long. After a while, it will show "wc: > stdin: read: Input/output error". Or we can ctrl C. > Version 5.2 Though already asked, what were you intending for it to do? -- Kerin Millar
Re: bug in bash
On Sun, May 12, 2024 at 03:55:21AM +0200, Quốc Trị Đỗ wrote: > I found a bug when i tried with syntax <(cmd). this is an example > cat <(wc -l) < bk What is "wc -l" supposed to read from? It counts lines of standard input, until EOF is reached. But its standard input is a terminal. And you're running it as a background process. I would *expect* this command to fail with an error message of some kind, because a background process shouldn't be allowed to read input from a terminal. > How to fix it? It doesn't last that long. After a while, it will show "wc: > stdin: read: Input/output error". Or we can ctrl C. Sounds appropriate. What's the "bug in bash" supposed to be? What did you think this command would do?
Re: bug in bash
On Mai 12 2024, Greg Wooledge wrote: > On Sun, May 12, 2024 at 03:55:21AM +0200, Quốc Trị Đỗ wrote: >> I found a bug when i tried with syntax <(cmd). this is an example >> cat <(wc -l) < bk > > What is "wc -l" supposed to read from? It counts lines of standard input, > until EOF is reached. But its standard input is a terminal. And you're > running it as a background process. > > I would *expect* this command to fail with an error message of some > kind, because a background process shouldn't be allowed to read > input from a terminal. Since the redirection fails and the cat command is never started, bash doesn't switch the terminal process group, and the background wc command goes on competing with bash for the terminal. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Re: bug in bash
On Sun, May 12, 2024 at 03:33:12PM +0200, Andreas Schwab wrote: > > On Sun, May 12, 2024 at 03:55:21AM +0200, Quốc Trị Đỗ wrote: > >> I found a bug when i tried with syntax <(cmd). this is an example > >> cat <(wc -l) < bk > Since the redirection fails and the cat command is never started, bash > doesn't switch the terminal process group, and the background wc command > goes on competing with bash for the terminal. Ah... I assumed bk was an existing file. hobbit:~$ cat <(wc -l) <.bashrc wc: 'standard input': Input/output error 0 hobbit:~$
Re: bug in bash
On Sun, May 12, 2024 at 4:33 PM Andreas Schwab wrote: > Since the redirection fails and the cat command is never started, bash > doesn't switch the terminal process group It does on my computer: 554 ioctl(255, TIOCSPGRP, [554]) = 0 553 execve("/usr/bin/wc", ["wc", "-l"], 0x55706d7bac10 /* 30 vars */ 554 +++ exited with 1 +++ But it doesn't change the process group ID of `wc' to its PID, so it ends up in the foreground process group with bash. See: $ cat <(bash -c 'enable setpgid; setpgid $$ $$; wc -l')
Re: bug in bash
On Mai 12 2024, Greg Wooledge wrote: > Ah... I assumed bk was an existing file. > > hobbit:~$ cat <(wc -l) <.bashrc > wc: 'standard input': Input/output error > 0 > hobbit:~$ Even then there can be a race when the foreground command finishes fast enough that bash switches the terminal process group back before the background process starts reading from the terminal (won't happen in this example since the cat command blocks on reading the process substitution file). -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."