I know that tty line discipline processes special characters (such as ^C, ^? and etc), but it is only about input from pty master device. But what about input from pty slave device? What tty line discipline does with input from pty slave device? Where can I find some code examples?


Line discipline doesn't apply to pty master device, which is simply a interface to receive or send bytes to "generic tty".

A generic tty is basically a tty device (either /dev/ttyx or pty slave device) with a line discipline, which transform the bytes from another end (either kernel terminal emulator or pty master device) into certain signals or do line-buffer-editing

  • So the line discipline doesn't have its own device? But where bytes sent from pty master device goes to exactly? They can't be transferred directly to pty slave device, because in such case a program would see absolute special characters (like ^C) – TwITe Jul 12 '19 at 13:25
  • Line discipline is a property of the generic tty, not exposed as file handler by kenerl. Bytes sent from pty master to slave is firsly handled by line discipline, so slave don't always get the exactly same data send by master.@TwlTe unix.stackexchange.com/questions/116629/… – 炸鱼薯条德里克 Jul 12 '19 at 15:00
  • Thanks, now I understand how tty line discipline intercepts data. But there is another question: how data being read from pts device? I've found write method: github.com/torvalds/linux/blob/master/drivers/tty/n_tty.c#L2301 which will call pty_write function of pts device: github.com/torvalds/linux/blob/master/drivers/tty/pty.c#L111. But I can't find read() method realization neither in tty line discipline nor in pts driver. So how scanf function behaves when trying to read from tty? – TwITe Jul 12 '19 at 15:51
  • Also, if tty line discipline is related to all tty devices, shouldn't it process ^C char when it comes to /dev/ttyN device and send SIGINT somewhere? Why master terminal gets ^C char or "^?"? – TwITe Jul 12 '19 at 16:25
  • 1
    but /dev/tty2 should be set to raw mode while we are in X, otherwise special characters will be processed before they could have chance to be transferred to the terminal emulator, isn't it? So I think X does it when loads to the current Virtual Terminal – TwITe Jul 14 '19 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.