157 points · by natex · 14y ago · 46 comments
What I love is how they come up with different names for different signals that kill/suspend processes:
`SIGHUP`, `SIGINT`, `SIGQUIT`, `SIGABRT`, `SIGKILL`, `SIGTERM` and `SIGSTOP`!
7 different combinations of SIG and a verb that means "terminate/kill/stop/close/quit/suspend", and it's not that confusing (once you get your head around it). Must have been quite a challenge!
E.g., "HUP" means hangup, and indeed, that's what you get when your modem hangs up accidentally! When handled by an application, it often is treated appropriately (e.g., the handler might trigger an autosave before quitting).
"INT" means "interrupt", and usage follows that sense -- it more likely than others to be ignored/repurposed (e.g. to quit back to some application prompt rather than killing the application entirely).
"ABRT" means "abort", and is typically used as a last-ditch means of killing the program when an internal error is detected.
"KILL" is more draconian than any other; there is no recovery possible.
etc.
"There's an important difference here: Writing to a TTY which is stopped due to flow control, or due to lack of kernel buffer space, will block your process, whereas writing to a TTY from a background job will cause a SIGTTOU to suspend the entire process group. I don't know why the designers of UNIX had to go all the way to invent SIGTTOU and SIGTTIN instead of relying on blocking I/O, but my best guess is that the TTY driver, being in charge of job control, was designed to monitor and manipulate whole jobs; never the individual processes within them."
Can anyone provide any more insight about this?
IMHO I think this all needs to be replaced with something sane. VT100 is obsolete, and we can now spare a few more BPS for a better terminal layer. Wasn't so long ago that if you left capslock on, something (getty?) on the Linux console would assume your terminal was one of those olde-worlde 6-bit ones, and stop using lowercase letters...
If anyone is curious how to do that (useful if you want your terminal application to handle escape key presses for example), this is the basics of it:
tcgetattr(master_controlling_tty, &term_settings);
cfmakeraw(&term_settings); /* set raw mode */
term_settings.c_cc[VMIN] = 1; /* minimum of 1 character per read */
term_settings.c_cc[VTIME] = 1; /* 1 decisecond timeout for read */
tcsetattr(master_controlling_tty, TCSANOW, &term_settings); /* write changes back to the tty */
Then if a read on your tty only returns the escape character, you know it was the escape key and not arrow keys or whatever.. unless there is some decent lag.. ;)It's fairly simple to do, but certainly hackish.
It seems that we're in the process of replacing it with web tech, which may or may not meet your definition of "something sane"...
There are many web systems being developed as business front-ends today that would suck less were they menu and form-driven terminal apps with a couple of web screens for reports. (or a websockets arrangement where the terminal could render certain things to an associated browser when appropriate)
There are a lot of complexities introduced by the need to handle situations we may never again encounter. The challenge is to make everything simpler, not only in lines of code, but in abstractions.
There is a program (called IIRC vt100) on Plan 9 that is used to talk to TTYs and serial ports, but it is rarely used, and it is the only part of Plan 9 that incorporates TTY-related concepts. Nor are signals a part of Plan 9, having been replaced by something called notes, which are conceptually different and simpler in concept and implementation.
I remember delving into the documentation of the stty command on Linux a few times in the 1990s. How I wish I could have those hours back (so I could do something more fun or more productive with them).
But everybody learns what they need to learn, even if it is setting the backspace/del keys to something visualy complient.
Knowing a tty and VT commands you can do some realy simple clever stuff, like find certain people logged in and there tty and cat append information to there screens and if they have terminals with extra sub lines you can sends a string that will memorise the screen cursor position, reposition cursor to the lower lines and display your text and then restore the cursor position. A very easy and simple way to instantly alert logged on users in certain groups. Can do all that in shell script easily. So knowing how things work and there capabilities and even there history and background so you understand why they are the way they are and from that appreciete there limitations. Then you can start doing some realy fun things. Again, nice read as verifys what you know and will fill in some worthy blanks.
http://jstn.cc/post/8692501831
http://jstn.cc/post/13476503553
http://jstn.cc/post/10831555077
http://www.fastcodesign.com/1665509/digital-archaeology-hack...
I've done it with an ADM-3A from the 70s too, it's just. Not. That. Tough.
http://imgur.com/bRnST here's me, years back, hacking on a VT 220
Original vi has what is called 'open mode', which is effectively a one-line window intended for printing terminals. Neither nvi nor vim provide this, but line mode (ex) is more efficient anyway.