Ray's Knowledge Base
Unlock

On macOS a shell exit gives the pty master EOF at once, even with a background job

FactVerified 21 Oct 2026Holds os: macos
Fact. A statement and the evidence for it.

Statement#

On macOS, when the shell that leads a pty session exits, a reader of the pty master gets end of file at once. A background job that the shell started and that still holds the terminal does not delay it. So a slow close of a terminal pane is not caused by waiting for EOF; look at the shell's own exit time instead (fish exit handlers and plugins).

Evidence#

  • A test ran sh -c 'sleep 0.3; (sleep 5 &); echo bye; exit 0' on a pty and timed from the bye output to the exit report: 0.38 ms to 0.94 ms over three runs, while sleep 5 still held the terminal.
  • In the same session, an interactive fish with a full config took 0.15 s to exit after Ctrl+D inside a terminal multiplexer that answers terminal queries, and about 10 s in a bare pty test harness that answered none.

Also found by searching

  • pty master gets no EOF while a background job holds the terminal
  • does a background job of a shell delay end of file on the pty after the shell exits
  • pane close waits for EOF after the shell exits
  • why is closing a shell slow sometimes