Linux console interface - Linux

This is a discussion on Linux console interface - Linux ; Hi all I am writing an operating system, and want to provide a compatibility interface for Linux console applications. Besides the obvious issues of supporting the Linux system calls and executable formats, there is the issue of providing a correct ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Linux console interface

  1. Linux console interface

    Hi all

    I am writing an operating system, and want to provide a compatibility
    interface for Linux console applications. Besides the obvious issues
    of supporting the Linux system calls and executable formats, there is
    the issue of providing a correct simulation of the STDIN, STDOUT and
    STDERR interface. However, I find that I have a lack of understanding
    about how the console interface works. I am wondering if anybody can
    provide me with links to information on this. In particular I have the
    following questions:

    1. How is STDIN/STDOUT/STDERR opened? Is this done by getty, and then
    all applications descended from getty just inherit this?

    2. I know that keyboard input is obtained by reading STDIN and screen
    output is acheived by writing to STDOUT. How do you send the console
    configuration options. You can do this via the termios functions of
    the C library, but does the C library acheive this using ioctls? I
    think it does, but I thought console ioctls may change between kernel
    versions. Should I just support the latest kernel version and risk old
    applications breaking if they do ioctls directly (that is not through
    termios)?

    3. What C module is the top-level terminal driver in the Linux kernel.
    That is, the one that is attached to major char device 4? Also, what
    is the association between the terminal driver and /dev/console. They
    seem to be two separate devices (/dev/console is on major number 5)

    regards
    MQ


  2. Re: Linux console interface

    MQ wrote:
    > Hi all
    >
    > I am writing an operating system, and want to provide a compatibility
    > interface for Linux console applications. Besides the obvious issues
    > of supporting the Linux system calls and executable formats, there is
    > the issue of providing a correct simulation of the STDIN, STDOUT and
    > STDERR interface. However, I find that I have a lack of understanding
    > about how the console interface works. I am wondering if anybody can
    > provide me with links to information on this. In particular I have the
    > following questions:
    >
    > 1. How is STDIN/STDOUT/STDERR opened? Is this done by getty, and then
    > all applications descended from getty just inherit this?
    >
    > 2. I know that keyboard input is obtained by reading STDIN and screen
    > output is acheived by writing to STDOUT. How do you send the console
    > configuration options. You can do this via the termios functions of
    > the C library, but does the C library acheive this using ioctls? I
    > think it does, but I thought console ioctls may change between kernel
    > versions. Should I just support the latest kernel version and risk old
    > applications breaking if they do ioctls directly (that is not through
    > termios)?
    >
    > 3. What C module is the top-level terminal driver in the Linux kernel.
    > That is, the one that is attached to major char device 4? Also, what
    > is the association between the terminal driver and /dev/console. They
    > seem to be two separate devices (/dev/console is on major number 5)


    There's a lot of answers in "Linux Application Development (2nd Edition)".

  3. Re: Linux console interface



    >
    > 1. How is STDIN/STDOUT/STDERR opened? Is this done by getty, and then
    > all applications descended from getty just inherit this?
    >
    > 2. I know that keyboard input is obtained by reading STDIN and screen
    > output is acheived by writing to STDOUT. How do you send the console
    > configuration options. You can do this via the termios functions of
    > the C library, but does the C library acheive this using ioctls? I
    > think it does, but I thought console ioctls may change between kernel
    > versions. Should I just support the latest kernel version and risk old
    > applications breaking if they do ioctls directly (that is not through
    > termios)?
    >
    > 3. What C module is the top-level terminal driver in the Linux kernel.
    > That is, the one that is attached to major char device 4? Also, what
    > is the association between the terminal driver and /dev/console. They
    > seem to be two separate devices (/dev/console is on major number 5)
    >



    Is any one able to answer my questions?

    MQ


  4. Re: Linux console interface

    MQ wrote:

    >
    >
    >>
    >> 1. How is STDIN/STDOUT/STDERR opened? Is this done by getty, and then
    >> all applications descended from getty just inherit this?
    >>
    >> 2. I know that keyboard input is obtained by reading STDIN and screen
    >> output is acheived by writing to STDOUT. How do you send the console
    >> configuration options. You can do this via the termios functions of
    >> the C library, but does the C library acheive this using ioctls? I
    >> think it does, but I thought console ioctls may change between kernel
    >> versions. Should I just support the latest kernel version and risk old
    >> applications breaking if they do ioctls directly (that is not through
    >> termios)?
    >>
    >> 3. What C module is the top-level terminal driver in the Linux kernel.
    >> That is, the one that is attached to major char device 4? Also, what
    >> is the association between the terminal driver and /dev/console. They
    >> seem to be two separate devices (/dev/console is on major number 5)
    >>

    >
    >
    > Is any one able to answer my questions?
    >
    > MQ


    Try thinking of it this way; STDIN/STDOUT/STDERR are all a gift to the
    developer from the OS/API/ABI, they are opened for him before the program
    starts and are closed automatically upon program exit. It is a very useful
    part of OS support for IO redirection. Lots of terminals connected to the
    computer was very much part of the computing environment when it was
    developed. ncurses, termcap, and termio were all part of the original
    multiple users per CPU model for unix.

    --
    JosephKK
    Gegen dummheit kampfen die Gotter Selbst, vergebens.**
    --Schiller

  5. Re: Linux console interface

    "MQ" wrote:
    >
    >Is any one able to answer my questions?


    Russell offered you a very good answer.

    >> 1. How is STDIN/STDOUT/STDERR opened? Is this done by getty, and then
    >> all applications descended from getty just inherit this?


    The best thing about Linux is that you can go look it up. You have the
    source code.

    Remember that stdin/stdout/stderr do not necessarily connect to a console.
    Consider:
    ls -l > savethis

    In this case, the shell is going to have to open "savethis" and pass the
    handle as "stdout". Without any redirection, the shell must duplicate the
    stdout handle it received. I would guess that getty is probably the one
    that starts it all.

    >> 2. I know that keyboard input is obtained by reading STDIN and screen
    >> output is acheived by writing to STDOUT. How do you send the console
    >> configuration options. You can do this via the termios functions of
    >> the C library, but does the C library acheive this using ioctls?


    Yes. Many programs just make the ioctl calls directly and bypass termios.

    >> I think it does, but I thought console ioctls may change between kernel
    >> versions. Should I just support the latest kernel version and risk old
    >> applications breaking if they do ioctls directly (that is not through
    >> termios)?


    Theoretically, this is true. However, the terminal control ioctls have
    been stable for many decades. They were present in the early versions of
    Unix, and no kernel developer who hoped to retain his gonads would propose
    changing them now.

    >> 3. What C module is the top-level terminal driver in the Linux kernel.
    >> That is, the one that is attached to major char device 4? Also, what
    >> is the association between the terminal driver and /dev/console. They
    >> seem to be two separate devices (/dev/console is on major number 5)


    Major number 4 handles the virtual terminals for the system's keyboard and
    monitor, as well as terminals coming in via serial ports. Major number 5
    is used for the "current" virtual terminal and for outgoing serial
    connections. A book, or the source code, would help you clear this up.
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

+ Reply to Thread