What happens to your input - inside the operating system


next up previous contents
Next: What happens to your input - inside Prolog
Up: Operating systems
Previous: Operating systems
Back: to main list of student notes

What happens to your input - inside the operating system

 

To remain in control - to give everyone a fair share of the machine - the operating system has to take charge of everything that goes into it, including your input. Generally, when you press a key, the character you typed gets sent to a storage area called a buffer inside the operating system. When you press another key, the same happens. It continues happening until you hit RETURN. When this happens, the operating system has collected a whole line of input, and it now sends this all at once to your program.

Why does the operating system store input in this way? Partly for efficiency. It's quicker to batch up the characters and send a whole batch to the terminal in one go than it is to send them one-by-one, because there's a constant overhead associated with every transmission. Partly for historical reasons, in that early computers worked on punched cards, and programming languages were designed to fit one sentence on each card. With such languages, you might as well wait until the whole card has been read before sending any of it.

The important point then is that, most of the time, whatever you type gets held by the operating system, and will not get to Prolog (or whatever program you are talking to) unless you press RETURN. You can visualise this if you imagine each character moving along a conveyer belt from the terminal to the operating system. The latter puts each character into a box. Only when it sees a RETURN does the system send the entire box (the line) on to Prolog.

If you forget RETURN, it is easy to think that Prolog is just being very slow to deal with your input, when in fact it never even receives it. This is why I keep emphasising the need for RETURN.

Having said all this, it's worth noting that programs can, if absolutely necessary, bypass the buffering process and respond to characters as soon as they're typed. Because it's inefficient to do so, most programs don't bother. However, some do. These include editors (such as Ved), where it's essential that you see each character as soon as you've typed it. The Eden ``manual bug'' does the same - you can type actions such as f and b without having to hit RETURN afterwards. When learning to use a new program, always make sure you know whether RETURN is needed after a command.


next up previous contents
Next: What happens to your input - inside Prolog
Up: Operating systems
Previous: Operating systems
Back: to main list of student notes



Jocelyn Paine
Thu Feb 15 00:11:40 GMT 1996