Hacker News new | past | comments | ask | show | jobs | submit login
The TTY Demystified (2008) (linusakesson.net)
146 points by dp-hackernews on April 24, 2022 | hide | past | favorite | 22 comments



I've read and re-read about all those many quirks a lot of times over the decades, and some of the things I understand to an extend where I know what the issue is when something breaks... but man, the interactions between tty/pty, terminal (emulator), shell, screen, ssh and locales still sometimes make me want to scream.

Nothing better than sshing into a random system and getting a ~ when you hit backspace.


> Nothing better than sshing into a random system and getting a ~ when you hit backspace.

Or having the backspace print as a space, but still being registered as a backspace. That one threw me the first time I ran into that.


I used to think the unix way of doing this was overly baroque, till I had to figure out how a terminal emulator worked in Windows, which requires an actual instance of the windows default terminal program (con.exe I think?) be drawn on the screen. So if you want to grab the IO from a terminal program (say to make your own terminal emulator), the standard solution is to draw a windows terminal off the boundry of your monitor somewhere and scrape the text out and send it to your program.*

*(I think this situation has improved somewhat in recent years with Windows Console?, but I haven't had a chance to play with that yet).


I regularly re-read this article myself and refer new Linux devs on our team to it. It's pretty incredible that the system of PID/SID/PGID has survived under the hood of Linux (and Unix) for this many decades.


And I'm guessing you could say we're too entrenched to change it?



Thanks! Macroexpanded:

The TTY Demystified (2008) - https://news.ycombinator.com/item?id=26803109 - April 2021 (35 comments)

The TTY demystified (2008) - https://news.ycombinator.com/item?id=17765683 - Aug 2018 (12 comments)

The TTY demystified (2008) - https://news.ycombinator.com/item?id=13571055 - Feb 2017 (43 comments)

The TTY demystified - https://news.ycombinator.com/item?id=10631513 - Nov 2015 (40 comments)

The TTY demystified (2008) - https://news.ycombinator.com/item?id=10064657 - Aug 2015 (31 comments)

The TTY demystified - https://news.ycombinator.com/item?id=8094186 - July 2014 (21 comments)

The TTY Demystified - https://news.ycombinator.com/item?id=4544318 - Sept 2012 (46 comments)

The TTY demystified - https://news.ycombinator.com/item?id=4062981 - June 2012 (17 comments)

The TTY demystified - https://news.ycombinator.com/item?id=658155 - June 2009 (13 comments)


Probably lots of other people have suggested this, but in case not: have you considered a “meta-page” that coalesces multiple submissions into one?


When the various discussions were years apart, like here, I suspect it would elide too much context to coalesce them.

But for submissions of the same vintage, it might be a good idea, and in fact not so different than the thread merging we already (but unsystematically) do.


Cool, thank you!


Kinda neat, thanks.


Minor sidenote / hopefully welcome feedback:

When pasting HN link lists like this, it's extra considerate to include the dates and comment counts, since sometimes stories have little or no discussion. Clicking through the links blindly wastes human time, especially for a longer list such as your post.


1. Generally speaking, dates are useful, but this is a link to article from 2008, so I'm not sure if previous submissions dates would be all that useful.

2. All links are to previous _discussions_, none are to discussion-less submissions.


As a venerable software philosopher said,

    That the concept of 'pty' still exists in the year 2009 is quite fucking
    amazing. I'm surprised we don't carry punchcards around anymore.
        --uriel
You are missed, Uriel. The world needs you now more than ever.


Punch holes were used in the Netherlands for a long time on bank transfer cards :) they'd be sent to "Postgiro" subscribers well into the 2000s.

Kinda cool because I never experienced the punch card era. I expect most of us here didn't.

PS who is Uriel? I only joined here a year or so ago and didn't hear of them before.




Basically, the TTY driver keeps track of the foreground process group id, but only in a passive way. A user process can affect the behavior of any TTY device by manipulating the corresponding device file under /dev. For example, a user process can send a signal to the TTY driver, which will then suspend the process. TTY driver keeps track of the size of the connected terminal, but this information has to be updated explicitly, by the terminal emulator or even by the user. The TTY driver is a passive object.


For anyone new to the topic; don't panic at the size of the vertical scrollbar in the article - the majority of it is comments! The article itself is succinct and not a huge read.


SIGSTOP and SIGCONT are also really useful with GUI apps. I use them when I want to pause a major app like Firefox but don't want to sleep the entire machine.


What use case do you have for pausing Firefox?


Minimising power usage while keeping the system as a whole running. "Light sleep mode" as it were.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: