Skip to content

Bun.Terminal: Ctrl+C (\x03) does not send SIGINT to foreground process #25832

@whoiskatrin

Description

@whoiskatrin

Description

When using Bun.Terminal with Bun.spawn, writing \x03 (Ctrl+C / ETX character) to the terminal does not send SIGINT to the foreground process group. The character is passed through to the PTY but does not trigger signal handling.

Steps to Reproduce

const terminal = new Bun.Terminal({
  cols: 80,
  rows: 24,
  data: (term, data) => {
    process.stdout.write(data);
  }
});

const proc = Bun.spawn(['/bin/bash'], {
  terminal,
  cwd: '/tmp',
  env: { TERM: 'xterm-256color', ...process.env }
});

// Later, when user presses Ctrl+C:
terminal.write('\x03');  // This should send SIGINT but doesn't

Expected Behavior

Writing \x03 to the terminal should cause the PTY driver to send SIGINT to the foreground process group, similar to how a real terminal handles Ctrl+C.

Actual Behavior

The \x03 character is written to the PTY but no signal is sent. Long-running commands like sleep 100 cannot be interrupted with Ctrl+C.

Workaround

Currently we work around this by intercepting \x03 and manually calling process.kill('SIGINT'):

if (data === '\x03') {
  proc.kill('SIGINT');
  terminal.write(data); // Still write to show ^C
  return;
}
terminal.write(data);

However, this only kills the shell process itself, not necessarily the foreground process group (e.g., if bash spawned a subprocess).

Environment

  • Bun version: 1.2.17+
  • OS: Linux (tested in Docker container on Ubuntu 22.04)
  • Architecture: x86_64

Additional Context

The same issue likely applies to other control characters like:

  • \x1a (Ctrl+Z) → SIGTSTP
  • \x1c (Ctrl+) → SIGQUIT

In a traditional PTY setup, the terminal driver (configured via stty) handles these control characters and sends the appropriate signals to the foreground process group.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions