The ConsoleMe page, the one about Virtual Terminals.




Paragraphs in this page are:

Theory
Practice



Theory

Considering command line, every terminal we see in Linux is virtual.
In other words, our screen simulates one or many hardware terminals.
So, in in the ttys, when we press alt F1 alt F2 etc. we circle around terminals in a single keyboard-monitor-mouse combination.
Linux Distros usually boot with 6 ttys (or other virtual terminal devices) and you can change the number with ease (I reduced it to 4).

for this See ConfigMe - inittab subpage.

Furthermore, an application can initialize in a new terminal, leaving the rest of the others still available.

So, think of ttys as Virtual Terminals in a single keyboard-monitor-mouse
combination where you could initialize more than the specified ones.

   
Q: What's a real terminal?
A: A character terminal is generally a monitor and keyboard device combination
that connects to a central processing unit through a serial port for example,
and interacts with the characters it receives. It is dumb, meaning that it has not
processing power of it's own. The days when the processing units were big as
rooms, users logged in via dozens of dumb terminals.

Q: Is there another terminal type?
A: Yes, the X terminal. X terminals are keyboard-monitor-graphics card-network
card device combinations that interact to graphics data through for example,
a network cable. Allthough are not "dumb", the processing power is still
centralized to one or many remote proccessing units.

In both modern types, you can attach a mouse easily.

Since most computers already have the hardware that an X terminal has, they can easily
simulate the X terminal role.

Inside a Gui, character terminals are handled like windows. We can start as many as
we want, plus minimize, move, maximize, cascade them etc.


Keep in mind that Virtual Terminals can be in graphics mode as well.

A vt (vc or tty) in graphics mode does not rely on the Bios to output data and can choose among many resolutions and fonts.

But do not confuse a graphics mode vt with X.




Practice


Handling a terminal in a Gui is not a problem to any user.

We are going to learn how to operate tty terminals.


1) Operation between terminals


Changing terminals:
With keyboard combinations alt F1 alt F2 etc. we change to the corresponding
terminal number.
We can also use alt [left or right] arrow combination to go to the previous-next terminal.

If logged on, we can also do this through the command line:
   chvt 1
   chvt 2 etc. will change to corresponding tty.

This command will output the tty device we are in:
   tty
   /dev/tty2 might be the answer.

But if we do this via a Gui terminal like xterm:
   tty
   /dev/pts0 Remember, we are not in a tty in this case.

This command initializes a new virtual terminal:
   openvt mc opens Midnight Commander in a new tty
If the  new tty is 7, then alt F7 or chvt 7 will take us there.
So, the old one is free for use.

If we exit mc the new virtual terminal closes.
With deallocvt we free all unused resources.

So, if we type openvt bash, we initialize bash in a new tty.

tty chvt and openvt commands can be used in scripts.

Operation between terminals is powerful, but individual terminals are also powerful.


2) Operating a single terminal.

This paragraph applies to tty And Gui terminals

We are going to use a single terminal i.e. tty 1
top (a full screen text mode program that monitors processes)
ctrl z   we froze "top" to the backround. A command line is available.
[1]+  Stopped top bash gives us some info.
mc       we call mc, too
ctrl z   we froze "mc" to the backround. a command line is available.
[2]+  Stopped /usr/bin/mc bash gives us some info.
We can do whatever we want with the command line plus:
jobs   informs about jobs
[1]-  Stopped  top bash gives us some info.
[2]+  Stopped  /usr/bin/mc bash gives us some info.
Then we can recall whatever we want:
fg 1 top will be up
ctrl z freeze top in the backround again
fg 2 mc will be up
Exit mc, fg 1 exit top with q

Q: Why is the application frozen in the backround?
A: Some full screen console applications behave strangely when active in the backround.
That's why an application is put in the backround initially frozen.

   But, if you have an application that gives simple data to the standard output like cp
   you can ctrl z it and then
   bg make it active to the background. When job done, exits safely.
   Please Do This If you have a real job to be done.
   
So, remember: Do not make applications like mc active in the backround.

A command like cp can be put in the background AND active this way:
   cp [parameters] &

How to kill applications in the backround:
call top and mc, and freeze both in the backround.
jobs
[1]-  Stopped  top
[2]+  Stopped  /usr/bin/mc
if you called them in that order.
kill %1
kill %2 They may appear as jobs, but they are killed.



Scrolling the terminal

When output exceeds terminal rows then only the new output is shown. In simple words, the terminal "scrolls down".

How can we then see the previous output? Simply scrolling up.

X terminals scroll with the methods below:
scroll bar
mouse wheel
shift page up/page down

Additionally, Kde Konsole can be scrolled with shift up/down arrow.

Tty terminals can be scrolled with shift page up/page down.


Freezing the terminal

In Kde Konsole,  previous data can be scrolled while data output is occuring at the same time.

In the same occasion though, ttys and other x-terminals would return to the last position, not leaving us to "browse" the old data.

There is a method to "freeze" the terminal in such a situation.

Ctrl s freezes ttys, xterm & other X-terminals but not Konsole.
Ctrl q reactivates them.

If a working program needs to output data in a frozen terminal, it will wait till the terminal unfreezes again, to continue work.

A copy operation in verbose mode (cp -v) is an example.
But consider that not only common verbose output will wait for a working terminal. Warnings and errors will wait too.

Remember:
Freezing the terminal stalls the program that uses it, if output is needed.
Kde Konsole scrolled up while printing data does not freeze the program.



A small tip for Konsole
The user accustomed to ttys, while working in an X Terminal may miss the key combination to change between terminals.

The common alt-tab combination doesn't help a lot unless individual x terminals are called sequentially.

In the case of Konsole we have the luxury to operate more than one terminals.

shift [left or right] arrow changes between terminals in a single KDE Konsole instance.