8 ms·
What happens when you open a terminal and enter `ls’
- ktfth 4y agoAwesome content! Very interesting how the process of a tool deal with the wires behind the scenes.
- szgupta 4y agoThanks! It was fun to write this up. Glad you enjoyed :)
- szgupta 4y agoHey HN! I'm Suraj, one of the authors of this blog post. Andy (@acarl005) and I came up with the idea to write this post when we realized there weren't many existing resources on how a terminal works under the hood, end-to-end. If folks find this useful, we'd be happy to turn this into a series and dive deeper into sub-topics. Let us know what you think :)
- clam2718 4y agoThank you for your article and I would be grateful for a deep dive series on how a terminal works would be great.
- proper_elb 4y ago[flagged]
- stcroixx 4y agoGoogle asked me this in an interview.
- szgupta 4y agoHaha! The post was actually motivated by a common (interview) question: https://github.com/alex/what-happens-when https://github.com/alex/what-happens-when. We thought it would make for a fun adaptation for the terminal world
- amelius 4y agoWould you pass this test if instead you answered what would happen if you open a terminal in a made-up operating system and you essentially designed the whole thing in your answer?
- aliqot 4y agoI would prefer this answer, it shows an ability to create anew rather than memorize rote.
- anyfoo 4y agoI don't think rote memorization applies very much here. When I ask the question, we start out open, let the candidate drive, but ask lots of questions along the way, and at certain points get very detailed on aspects that we care about particularly (while skipping quickly over, for us, uninteresting ones). If you "rote memorized" both the high level view and the raw details so well that you can freely think and talk about it during the interview, I'd say you'd have to have had some experience as well.
- crystaln 4y agoNow with this article memorized one could answer this question with rote memorization. However most people are unlikely to have done that. Instead if someone can provide a good answer they are demonstrating a deep understanding.
- fragmede 4y agoI mean, points for creativity; it just depends on this made-up answer. If you're relying on transistors made up of unicorn farts and gumdrops, and the interviewer has no appreciation for whimsy, that's not gonna go over well. OTOH, if they do, that's bonus points. All I'm saying is that it's a gamble.
- anyfoo 4y agoI have asked this question in interviews before, with focus on low level OS aspects. It depends on whether your made-up OS includes the things we care about. I usually ask the question in an open way, but guide the candidate to "fast forward" past the (for us) boring parts, and focus on the interesting parts we are looking for along the way. If your OS covers the concepts we are looking for and the answers seem competent, sure, let's give it a try, but don't be surprised if we veer off of that. If the OS is too simple to cover everything (not unlikely for actually existing toy OS projects, I have one myself), we'd want to branch out to those concepts no matter whether you included them in your hypothetical OS or not. And if your made up OS is just too different, it might not apply either. In other words, ask yourself why this is part of the interview, and that should answer your question: Because you are going to work on a particular OS with particular characteristics.
- plantain 4y agoI had the same for SRE @ Google - really simple question that probes the entire free-form depth of your systems understanding.
- stcroixx 4y agoI guess you could leave out all the hardware aspects of it - that's why I think it's not a great question myself, just too wide.
- lloydjones 4y agoExcellent article! Thank you
- tipalti_layoff 4y ago[flagged]
- lordleft 4y agoGreat article. It's amazing how much ancient tech still pulsates in our sleek new machines.
- szgupta 4y agoThanks! Were there any topics in the blog that you think would benefit from more detail in a follow-up post?
- bkor 4y agoThings you might want to add: a) Escape sequence to set the "dynamic" terminal title b) how e.g. GNOME notifies you that a long running command has completed c) how e.g. GNOME asks if you are certain to close a terminal, but only in case you're not in a shell d) maybe readline or /etc/inputrc e) bash completions maybe? it's sort of in there already
- WalterBright 4y agoJust like our rat brains still in our heads.
- mrlonglong 4y agoWe aren't descended from rats, though. Lizard brains, maybe?
- imagetic 4y agoNice to see a fun topic on the front page.
- zokier 4y agoOne thing that is missing is the termcap/terminfo system. For funsies, you can try to run your session with TERM=dumb to get a retro experience :)
- nixpulvis 4y agoterminfo would be a good topic for a couple blogposts for sure. Back when I was first learning all this stuff I never felt like I truly understood all the intricacies of this system. I tried to understand back when alacritty made it's own entry, but a lot of things still feel somewhat arcane. Basically, it's a capability list though, IIUC.
- szgupta 4y agoYeah I like to think of it as a capability list as well. There was a brief footnote [12] about $TERM in the post, but terminfo could certainly be dissected further. [12](https://www.warp.dev/blog/what-happens-when-you-open-a-terminal-and-enter-ls#footnote-twelve https://www.warp.dev/blog/what-happens-when-you-open-a-termi...)
- crosser 4y agoThat article starts with too many inaccuracies to recommend it to anybody: - Teletypes were designed about a century before the era of mainframes. - Mechanical teletype did not have an "I/O driver" in it. - OS on Mainframe computers did not have a "Kernel", and neither "I/O driver", "Line discipline" or "TTY driver". This model was introduced with UNIX, the OS that ran on minicomputers. - Was ChatGPT used to write this article? ;) I've recently stumbled upon an article on the same topic, but containing competent and accurate information, I have a link because I recommended it to a friend: https://thevaluable.dev/guide-terminal-shell-console/ https://thevaluable.dev/guide-terminal-shell-console/
- acarl005 4y agoHi. I definitely took some liberties with terms here. For example, I said "I/O driver" instead of, say UART driver because I didn't want to get overly specific on the historical part. That wasn't the focus of this article. Thanks for linking this other one, as it fills in those parts well.
- kevin_thibedeau 4y ago> This model was introduced with UNIX The UNIX IO system was adapted from Multics.
- epolanski 4y agoThat's quite an unnecessarily toxic comment, besides all your criticism seems fixated with the introduction on teletypes. I enjoyed the blogpost, I trust the authors of a terminal emulator to give me a good overview on the topic and I enjoyed it.
- torben-friis 4y agoI’ve seen many times descriptions of how original teletypes work and how that influences modern terminals. However, something that I have not seen yet and I’d love to check is an attempt to redesign the terminal from scratch separating historical baggage from the parts that still make sense nowadays. How would a designer create this tool without the historical precedence? Is tradition holding us back? What new standards could we reach ?
- duckmysick 4y ago> ASCII text would be transmitted character-by-character over the wire as the user typed. How does that work exactly on a lower level, say the current? ASCII text would be decoded to the binary and 1s would be high voltage and 0s would be low? And if there's no data transmitted it would be all low voltage?
- netr0ute 4y agoIt still works the same way, just abstracted as individual characters and not specifically the implementations of electrical representations of keys. Every character is stateless, so whatever's before or after doesn't matter. So this means that some operations are a lot easier and a lot harder than they otherwise might be, because while you only have to make a decision for one character at a time, you need to keep an internal state if you want to display characters or do something with them as a whole.
- analog31 4y agoOn the old terminals, the wire sits at one voltage level until a character is transmitted. After that, the bits are spaced out at agreed-upon time intervals. So the receiver detects the first transition, and then reads and stores the bits by applying the same timing, then waits for the next character. Meanwhile, the value of that character, say an 8-bit number, is stored in a register, and typically the processor is interrupted. This gives the processor time to deal with each character before the next one is received. Oddly enough I could have answered the OP's question in an interview, 40 years ago, but stuff has gotten so complex that I can't even tell you what all of the layers of abstraction are.
- WalterBright 4y agoIn the olden days, I'd drive my Fred Flintstone car to work. Serial I/O was done by wire-wrapping a UART chip on the board, which handled all the dirty details. https://en.wikipedia.org/wiki/8250_UART https://en.wikipedia.org/wiki/8250_UART Though the UART chip I used was years earlier than that. Perhaps the Wikipedia article is wrong on that point.
- analog31 4y agols is not recognized as an internal or external command, operable program or batch file. ;-)
- szgupta 4y agoHaha, yeah we probably should have added a caveat that this is only applicable to Unix
- analog31 4y agoI assumed so, but then I got curious what would happen in a DOS window.
- kkielhofner 4y agoThankfully it works in Powershell on Windows. I lost any muscle memory for `dir` a long long time ago.
- waste_monk 4y agoUntil you hit something like "Get-ChildItem : A parameter cannot be found that matches parameter name 'lh'" and are jarringly reminded that this is not your old friend `ls` after all.
- JdeBP 4y agoThis is why, if I use a shorthand in PowerShell at all, I avoid using "dir", "ls", and the like. "gci" is at least not like any common Unix/BSD/PC-DOS/Windows/OS/2 command.
- warent 4y agoI want to use Warp but it has forced telemetry. Any roadmap for making this more private? Would happily give you my money
- exists 4y agoWarp actually made telemetry optional last month https://www.warp.dev/blog/telemetry-now-optional-in-warp https://www.warp.dev/blog/telemetry-now-optional-in-warp
- nixpulvis 4y agoNow let us compile the source without the code at all. A terminal should only do anything when the user types something and presses enter, and then it should only do what the user told it to do. The idea that it goes off to the network unasked is beyond invasive. But good move. The idea of a terminal tracking my typings and commands is pretty scary stuff, especially if I'm going to use this thing for security sensitive sessions.
- somehnguy 4y agoAnother issue is that when an update is available I need to be able to tell Warp that I don’t care at the moment. Due to the corporate software on my work Mac auto-updates fail. Ordinarily this isn’t a huge deal as I’ll just download the DMG and replace it manually. But Warp drops down an obtrusive overlay and you can’t dismiss it until you update. I tried to like it, but little forced choices like that sent me back to iTerm 2.
- deleted 4y ago[deleted]