kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* How are the standard file descriptors implemented?
@ 2020-10-07  6:11 Sebastian Fricke
  2020-10-08  3:01 ` linux lover
  2020-10-09  4:47 ` Valdis Klētnieks
  0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Fricke @ 2020-10-07  6:11 UTC (permalink / raw)
  To: kernelnewbies; +Cc: sebastian.fricke.linux

Hello,

after my current research on that topic, I fear that my question is
probably way too broad and unspecific, as there seem to be multiple
viable ways, so I try to narrow it down.
First of what is my motivation?
I try to implement these standard file descriptors within a practice
operating system, in order to get file-system specific system calls like
open, read, write and close to work.

What I currently (believe to) know:
- The standard file descriptors are an abstraction layer in between an
  output device like a monitor and an input device like a keyboard. In
  the old days, these were configured directly to the terminals.
- In glibc (https://github.com/bminor/glibc/blob/master/libio/stdfiles.c),
  they are defined there as FILE struct instances that associate to the
  specific file descriptors.
- I can locate the file descriptors of a specific process within Linux
  under: /proc/{process_id}/fd/{0,1,2}
    root@basti:/proc/self# ls -l fd
    total 0
    lrwx------ 1 root root 64 Oct  7 07:54 0 -> /dev/pts/4
    lrwx------ 1 root root 64 Oct  7 07:54 1 -> /dev/pts/4
    lrwx------ 1 root root 64 Oct  7 07:54 2 -> /dev/pts/4
    lrwx------ 1 root root 64 Oct  7 07:54 255 -> /dev/pts/4

  they all point to /dev/pts/4, if I look in the /dev/pts directory:

    root@basti:/dev/pts# ls -l
    total 0
    crw--w---- 1 basti        tty  136, 0 Oct  7 07:53 0
    crw--w---- 1 basti        tty  136, 1 Oct  6 20:59 1
    crw--w---- 1 libvirt-qemu tty  136, 2 Oct  4 16:27 2
    crw--w---- 1 basti        tty  136, 3 Oct  7 07:56 3
    crw------- 1 basti        tty  136, 4 Oct  7 07:56 4
    c--------- 1 root         root   5, 2 Oct  4 12:10 ptmx

  Here I can see that they all point to a character device, with the
  group tty. And I know that /dev/pts/4 is a pseudeo teletype, which is
  a slave of the ptmx multiplexor.

The gaps I currently have:
- Who creates that device /dev/pts/4 ? I was currently not able to
  locate this information.
- How is that device connected to my keyboard/monitor?
- Could I maybe create a simplified version, which just utilizes a file
  for STDIN, STDOUT, STDERR. That are created by the init process and
  inherited to all child processes? Maybe I could then redirect the
  keyboard output to the STDIN file, the STDOUT file to the monitor
  device etc.

Thanks in advance for any help!

Greetings
Sebastian


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-09  4:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07  6:11 How are the standard file descriptors implemented? Sebastian Fricke
2020-10-08  3:01 ` linux lover
2020-10-09  4:47 ` Valdis Klētnieks

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).