bug#80010: timeout echo vs. timeout cat
Collin Funk <[email protected]> Sun, 14 Dec 2025 19:08:28 -0800
| Newsgroups | gmane.comp.gnu.core-utils.bugs |
|---|---|
| Message-ID | <[email protected]> |
Code Con Carne via GNU coreutils Bug Reports <[email protected]> writes: > $ timeout 1s echo foo > pipe > > expected: times out after 1s > actual: never times out; ctrl-c to exit > > coreutils 9.4-3ubuntu6.1 amd64 In this example, your shell opens "pipe" for writing. There are no readers, so the shell is blocked. The 'timeout' command is not supposed to kill the shell, it's parent, so it doesn't. You can verify this yourself like so: $ mkfifo pipe $ timeout 1 echo foo > pipe & [1] 1483195 In another terminal window, we can see the process is 'bash' and check what it is doing: $ ps -p 1483195 PID TTY TIME CMD 1483195 pts/5 00:00:00 bash $ strace -p 1483195 strace: Process 1483195 attached openat(AT_FDCWD, "pipe", O_WRONLY|O_CREAT|O_TRUNC, 0666 So it is blocked opening "pipe". Returning to the original terminal window, we can read from "pipe": $ cat pipe foo [1]+ Done timeout 1 echo foo > pipe So the shell is unblocked and finishes executing the command. In the terminal window with 'strace' running, we can see that 'timeout' isn't invoked until after "pipe" is opened after being unblocked: $ strace -p 1483195 strace: Process 1483195 attached openat(AT_FDCWD, "pipe", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 dup2(3, 1) = 1 close(3) = 0 execve("/home/collin/.local/bin/timeout", ["timeout", "1", "echo", "foo"], 0x561e21977ae0 /* 86 vars */) = 0 I agree that this behavior isn't obvious. :) Collin