controlling terminal and virtual terminal - Unix

This is a discussion on controlling terminal and virtual terminal - Unix ; what's the difference between controlling terminal and virtual terminal? i got some information from man pages about them, here: $man 4 console NAME console - console terminal and virtual consoles DESCRIPTION A Linux system has up to 63 virtual consoles ...

+ Reply to Thread
Results 1 to 10 of 10

Thread: controlling terminal and virtual terminal

  1. controlling terminal and virtual terminal

    what's the difference between controlling terminal and virtual
    terminal?
    i got some information from man pages about them, here:

    $man 4 console
    NAME
    console - console terminal and virtual consoles
    DESCRIPTION
    A Linux system has up to 63 virtual consoles (character devices with
    major number 4 and minor number 1 to 63), usually called /dev/ttyn
    with 1 < n < 63. The current console is also addressed by /dev/console
    or /dev/tty0, the character device with major number 4 and minor
    number 0
    ........................................
    $man 4 tty
    NAME
    tty - controlling terminal

    DESCRIPTION
    The file /dev/tty is a character file with major number 5 and
    minor number
    0, usually of mode 0666 and owner.group root.tty

    but i can't understanding it? who can tell me the difference ?thanks/

  2. Re: controlling terminal and virtual terminal

    Xend schrieb:
    > what's the difference between controlling terminal and virtual
    > terminal?
    > i got some information from man pages about them, here:
    >
    > $man 4 console
    > NAME
    > console - console terminal and virtual consoles
    > DESCRIPTION
    > A Linux system has up to 63 virtual consoles (character devices with
    > major number 4 and minor number 1 to 63), usually called /dev/ttyn
    > with 1 < n < 63. The current console is also addressed by /dev/console
    > or /dev/tty0, the character device with major number 4 and minor
    > number 0
    > .......................................
    > $man 4 tty
    > NAME
    > tty - controlling terminal
    >
    > DESCRIPTION
    > The file /dev/tty is a character file with major number 5 and
    > minor number
    > 0, usually of mode 0666 and owner.group root.tty
    >
    > but i can't understanding it? who can tell me the difference ?thanks/


    AFAIK, a virtual terminal is a terminal that has no dedicated hardware,
    and therefore gets a /dev/pty* entry. So an xterm is a virtual terminal,
    but the system console is a real terminal.

    In contrast a virtual console is one of multiple terminals on a console
    that act like a regular console.

    A console in contrast to a normal terminal usually has additional
    features to access and modify parameters of the hardware. E.g. on Sun
    machines you can access the OBP (open boot prom prompt) from the
    console, but not from a regular terminal.

    HTH,
    Thomas

  3. Re: controlling terminal and virtual terminal

    2008-10-28, 22:10(-07), Xend:
    > what's the difference between controlling terminal and virtual
    > terminal?
    > i got some information from man pages about them, here:
    >
    > $man 4 console
    > NAME
    > console - console terminal and virtual consoles
    > DESCRIPTION
    > A Linux system has up to 63 virtual consoles (character devices with
    > major number 4 and minor number 1 to 63), usually called /dev/ttyn
    > with 1 < n < 63. The current console is also addressed by /dev/console
    > or /dev/tty0, the character device with major number 4 and minor
    > number 0


    Virtual consoles on Linux are the virtual consoles you may
    switch between by pressing , and so on. They
    are so called because the /real/ console (your keyboard and
    monitor) is used to serve several different consoles, one of
    which is active at a time (takes input from the keyboard and
    send display to the monitor), though applications can send stuff
    and read input even when they are not active via /dev/tty.

    > .......................................
    > $man 4 tty
    > NAME
    > tty - controlling terminal
    >
    > DESCRIPTION
    > The file /dev/tty is a character file with major number 5 and
    > minor number
    > 0, usually of mode 0666 and owner.group root.tty
    >
    > but i can't understanding it? who can tell me the difference ?thanks/


    That has not much to do with the virtual consoles. The
    controlling terminal is an attribute of a process. It's the
    terminal attached to a process. It controls it in that for
    instance pressing on that terminal sends a SIGINT to
    the processes that it controls and that are in its foreground
    process group, and those that are not in its foreground process
    group get a SIGTTIN or SIGTTOU if they read or write or do some
    ioctls to the terminal.

    Processes controled by a same terminal belong to a same
    "session". The session leader (the process that creates the
    session) is the one that /attaches/ to the terminal so that all
    its descendants are also controlled by that terminal (unless
    they themselves start a new session).

    Typically a session leader would be the process that executes
    "getty" on a terminal and later one "login" to log you in and
    later on your shell. Or in terminal emulators like xterm, it's
    the process forked by xterm that executes your shell.

    /dev/tty is a special device that /points/ to the controlling
    terminal. It behaves differently depending on which process
    accesses it. If /dev/tty3 is the controlling terminal of process
    p1, then if p1 writes to /dev/tty, it's as if it had written to
    /dev/tty3.

    It's handy when you want to get input from the user and bypass
    whatever the user might have redirected the standard input.
    Typically, commands like "passwd" read input (the password you
    enter) from /dev/tty, because they know it will be a really user
    that will type it in (though, you could use pseudo-terminals
    like when using "expect" to fool it).

    Since we're in comp.unix.programmers, something with controlling
    terminals you may want to be aware of: when writing daemon
    software (software that is not meant to have direct interaction
    with a user nor be bound to a login session), you want to be
    sure you *don'* have a controlling terminal, that's why you use
    setsid() to create a new session (which you can only do if
    you're not already a group leader which is why you often see
    daemons doing a first fork before), and then you want to avoid
    attaching to a terminal, which is why you want to use the
    O_NOCTTY flag every time you open a file which might be a
    terminal, or alternatively you can fork another time after
    creating the session to avoid being a session leader.

    Cheers,
    Stéphane

  4. Re: controlling terminal and virtual terminal

    Stephane CHAZELAS wrote:

    > 2008-10-28, 22:10(-07), Xend:
    >> what's the difference between controlling terminal and virtual
    >> terminal?
    >> i got some information from man pages about them, here:
    >>
    >> $man 4 console
    >> NAME
    >> console - console terminal and virtual consoles
    >> DESCRIPTION
    >> A Linux system has up to 63 virtual consoles (character devices with
    >> major number 4 and minor number 1 to 63), usually called /dev/ttyn
    >> with 1 < n < 63. The current console is also addressed by /dev/console
    >> or /dev/tty0, the character device with major number 4 and minor
    >> number 0

    >
    > Virtual consoles on Linux are the virtual consoles you may
    > switch between by pressing , and so on. They
    > are so called because the /real/ console (your keyboard and
    > monitor) is used to serve several different consoles, one of
    > which is active at a time (takes input from the keyboard and
    > send display to the monitor), though applications can send stuff
    > and read input even when they are not active via /dev/tty.
    >


    Excellent answer!

    I still have a question, what is the difference between Virtual consoles
    and Pseudo terminals? I thought they are the same, but I was wrong.
    Can you explain this a bit?

    Thank you!


  5. Re: controlling terminal and virtual terminal

    2008-10-30, 16:23(+00), WANG Cong:
    [...]
    >> Virtual consoles on Linux are the virtual consoles you may
    >> switch between by pressing , and so on. They
    >> are so called because the /real/ console (your keyboard and
    >> monitor) is used to serve several different consoles, one of
    >> which is active at a time (takes input from the keyboard and
    >> send display to the monitor), though applications can send stuff
    >> and read input even when they are not active via /dev/tty.

    [...]
    > I still have a question, what is the difference between Virtual consoles
    > and Pseudo terminals? I thought they are the same, but I was wrong.
    > Can you explain this a bit?

    [...]

    Thay have nothing to do with one another.

    virtual consoles have been explained above and are a linux
    thing. pseudo-terminals is a tool used to emulate a terminal. It
    is typically used by xterm, in.telnetd or expect.

    A process accesses a terminal by means of a /dev/tty. The
    idea being that what you type on the keyboard is accessible to
    an application that reads from that device and what what an
    application writes to that is displayed on the screen
    (simplified).

    There are several types of terminal, for instance, there's a
    terminal you plus on the serial line. Then what an application
    sends on /dev/tty is sent on the wire to that terminal that
    handles the displaying.

    There's a simple VGA console. What an application writes on
    /dev/tty is handled by the kernel that makes it display on
    the VGA screen.

    There are virtual consoles, where a "virtual console" is
    updated, and it's only displayed when the virtual console is
    active (as seen above).

    pseudo-terminals won't work by themselves. With a pseudo
    terminal, what an application writes to /dev/tty (which is
    the slave side of a pseudo-terminal) is sent to another
    application that controls the master side of the
    pseudo-terminal, and that application is responsible for doing
    something with that. For instance, xterm will read that to
    send X-Window request to update the display of its window.
    in.telnetd will send the data over the network to the "telnet"
    at the other end which will itself write it to the terminal
    device for display on the remote computer... expect will use it
    to fake a terminal (fake the user interactions).

    --
    Stéphane

  6. Re: controlling terminal and virtual terminal

    Stephane CHAZELAS wrote:
    >
    > Thay have nothing to do with one another.
    >
    > virtual consoles have been explained above and are a linux
    > thing. pseudo-terminals is a tool used to emulate a terminal. It
    > is typically used by xterm, in.telnetd or expect.
    >
    > A process accesses a terminal by means of a /dev/tty. The
    > idea being that what you type on the keyboard is accessible to
    > an application that reads from that device and what what an
    > application writes to that is displayed on the screen
    > (simplified).
    >
    > There are several types of terminal, for instance, there's a
    > terminal you plus on the serial line. Then what an application
    > sends on /dev/tty is sent on the wire to that terminal that
    > handles the displaying.
    >
    > There's a simple VGA console. What an application writes on
    > /dev/tty is handled by the kernel that makes it display on
    > the VGA screen.
    >
    > There are virtual consoles, where a "virtual console" is
    > updated, and it's only displayed when the virtual console is
    > active (as seen above).
    >
    > pseudo-terminals won't work by themselves. With a pseudo
    > terminal, what an application writes to /dev/tty (which is
    > the slave side of a pseudo-terminal) is sent to another
    > application that controls the master side of the
    > pseudo-terminal, and that application is responsible for doing
    > something with that. For instance, xterm will read that to
    > send X-Window request to update the display of its window.
    > in.telnetd will send the data over the network to the "telnet"
    > at the other end which will itself write it to the terminal
    > device for display on the remote computer... expect will use it
    > to fake a terminal (fake the user interactions).
    >


    Great thanks!

    So let me summerize:

    /dev/console is the real console device.
    /dev/ttyN are virtual consoles, expect /dev/tty0, which points
    to the current console.

    The followings are pseudo-terminals:

    /dev/tty is the current tty, i.e. the current termial.

    /dev/ptmx is Unix 98 master
    /dev/pts/* are Unix 98 slaves
    /dev/pty[p-za-e][0-9a-f] aer BSD masters
    /dev/tty[p-za-e][0-9a-f] are BSD slaves.

    Is the above correct? Please correct me if anything is wrong.




  7. Re: controlling terminal and virtual terminal

    2008-11-04, 20:06(+00), WANG Cong:
    [...]
    > So let me summerize:
    >
    > /dev/console is the real console device.
    > /dev/ttyN are virtual consoles, expect /dev/tty0, which points
    > to the current console.
    >
    > The followings are pseudo-terminals:
    >
    > /dev/tty is the current tty, i.e. the current termial.
    >
    > /dev/ptmx is Unix 98 master
    > /dev/pts/* are Unix 98 slaves
    > /dev/pty[p-za-e][0-9a-f] aer BSD masters
    > /dev/tty[p-za-e][0-9a-f] are BSD slaves.
    >
    > Is the above correct? Please correct me if anything is wrong.

    [...]

    Yes, except for /dev/console which is yet another /virtual/
    thing. It's the terminal that gets messages from the kernel (and
    from anything writing to /dev/console). It's like an alias
    for another terminal. A bit as if it were a symlink to the
    /selected/ terminal except that it behaves slightly differently
    in some corner cases.

    You select which terminal you want to be the "console" with the
    TIOCCONS ioctl, it doesn't have to be a virtual console. It's
    initialised via the console= parameter to the kernel boot
    parameters. In embedded Linux, it's more generally a serial
    console, it could also be a network console... The console(4)
    man page at least on debian is incorrect, I'll report that.

    You can use xterm's -C option for it to become the console. If
    you run xterm -C and then echo foo > /dev/console, the "foo"
    will appear on that xterm (note that you may need some special
    priviledges for that to work).

    --
    Stéphane

  8. Re: controlling terminal and virtual terminal

    >So let me summerize:

    What is this summary supposed to cover? All POSIX systems?

    >/dev/console is the real console device.


    On FreeBSD it refers to the system console, whatever hardware that
    happens to be (which might be at least the VGA display/keyboard or
    a serial port).

    >/dev/ttyN are virtual consoles, expect /dev/tty0, which points
    >to the current console.


    On FreeBSD (N is a character [0-9a-v]):
    /dev/ttydN are dialin serial ports (modems).

    /dev/ttyvN are virtual console devices that share console hardware.

    /dev/ttypN are pseudo-terminal slaves. There are provisions for
    using /dev/tty[pqrsPQRS]N if you need a lot of them. The corresponding
    masters are /dev/pty[pqrsPQRS]N. Some code, however, uses the
    pattern /dev/tty[p-za-oA-Z][0-9a-f] for pseudo-terminal devices.

    /dev/tty is the control terminal of the current process, and will fail
    to open if the process has no control terminal (e.g. run from cron).

    There is no /dev/tty0. Some earlier versions used /dev/tty00 and
    /dev/tty01 for serial ports.

    >The followings are pseudo-terminals:
    >
    >/dev/tty is the current tty, i.e. the current termial.
    >
    >/dev/ptmx is Unix 98 master
    >/dev/pts/* are Unix 98 slaves
    >/dev/pty[p-za-e][0-9a-f] aer BSD masters
    >/dev/tty[p-za-e][0-9a-f] are BSD slaves.
    >
    >Is the above correct? Please correct me if anything is wrong.


    I think you are trying to be too specific for the variety of systems
    out there.

  9. Re: controlling terminal and virtual terminal

    2008-11-05, 13:17(-06), Gordon Burditt:
    [...]
    >>Is the above correct? Please correct me if anything is wrong.

    >
    > I think you are trying to be too specific for the variety of systems
    > out there.


    I understood the question as being exlusively Linux. I should
    have mentionned that my answer was. Of course, virtual consoles
    as /dev/tty are Linux. BSDs have equivalent*s*, many other
    systems don't have virtual consoles.

    I don't think the Single Unix Specification says much about all
    that. One notes though:

    SUSv3> /dev/console
    SUSv3> The /dev/console file is a generic name given to the
    SUSv3> system console (see System Console). It is usually linked
    SUSv3> to an implementation-defined special file. It shall
    SUSv3> provide an interface to the system console conforming to
    SUSv3> the requirements of the Base Definitions volume of IEEE
    SUSv3> Std 1003.1-2001, Chapter 11, General Terminal Interface.

    There's also an entry for /dev/tty.

    --
    Stéphane

  10. Re: controlling terminal and virtual terminal

    Gordon Burditt wrote:

    >>So let me summerize:

    >
    > What is this summary supposed to cover? All POSIX systems?
    >
    >>/dev/console is the real console device.

    >
    > On FreeBSD it refers to the system console, whatever hardware that
    > happens to be (which might be at least the VGA display/keyboard or
    > a serial port).
    >
    >>/dev/ttyN are virtual consoles, expect /dev/tty0, which points
    >>to the current console.

    >
    > On FreeBSD (N is a character [0-9a-v]):
    > /dev/ttydN are dialin serial ports (modems).
    >
    > /dev/ttyvN are virtual console devices that share console hardware.
    >
    > /dev/ttypN are pseudo-terminal slaves. There are provisions for
    > using /dev/tty[pqrsPQRS]N if you need a lot of them. The corresponding
    > masters are /dev/pty[pqrsPQRS]N. Some code, however, uses the
    > pattern /dev/tty[p-za-oA-Z][0-9a-f] for pseudo-terminal devices.
    >
    > /dev/tty is the control terminal of the current process, and will fail
    > to open if the process has no control terminal (e.g. run from cron).
    >
    > There is no /dev/tty0. Some earlier versions used /dev/tty00 and
    > /dev/tty01 for serial ports.
    >
    >>The followings are pseudo-terminals:
    >>
    >>/dev/tty is the current tty, i.e. the current termial.
    >>
    >>/dev/ptmx is Unix 98 master
    >>/dev/pts/* are Unix 98 slaves
    >>/dev/pty[p-za-e][0-9a-f] aer BSD masters
    >>/dev/tty[p-za-e][0-9a-f] are BSD slaves.
    >>
    >>Is the above correct? Please correct me if anything is wrong.

    >
    > I think you are trying to be too specific for the variety of systems
    > out there.


    Sorry, I should mention that I wanted to talk about Linux.

    Anyway, thanks very much for your answer!



+ Reply to Thread