title: In detail, what happens when you press Ctrl-C in a terminal?
body: <p>In detail, what happens when you press Ctrl-C in a terminal?  Yes, I know that it sends SIGINT, but what steps does it take to get there?</p>
  
  <p>I have done some research so I think I understand most of the picture, but not all of it.</p>
  
  <p>For the sake of pedagogy, I will assume we are running a terminal emulator, xterm, in an X session.  The terminal is running the Bash shell, and the shell is currently running some long running pipeline consisting of multiple processes in the foreground.</p>
  
  <ol>
  <li>I press Ctrl-C in the keyboard.</li>
  <li>X sends the keyboard event to xterm.</li>
  <li>xterm translates the Ctrl-C keyboard event and sends it to the pseudo-tty master file descriptor it is holding? (Some magic happens)</li>
  <li>The kernel detects that some special SIGINT event happens on the pseudo-tty, and finds the session whose controlling terminal is this tty.  It sends SIGINT to the current foreground process group of that session, which includes only the processes in our pipeline.</li>
  </ol>
  
  <p>My question is, is my understanding so far correct, and how exactly does xterm tell the kernel to send SIGINT to the session with a given controlling terminal?</p>