Hello Guys, We all know that when an application writes to stdout, data ends up in the console. Okey so if I m on my development board and if I run an app, all the prints comes to the console (eg /dev/ttyS0). If I m on any server using ssh and all apps prints comes on my putty (eg through /dev/pts/176). Where is the code which maps fd 1 to the console in kernel? If you guys have any pointers, please share. While opening a device (for eg /dev/something), the vfs calls that drivers, whose major and minor number matches. But in case of stdout, how vfs resolves the write to the fd 1 and send it to the corresponding console driver? Thanks, Arun
On Mon, Apr 23, 2012 at 03:45:00PM +0530, Arun KS wrote:
Hello Guys,
We all know that when an application writes to stdout, data ends up in the console.
Okey so if I m on my development board and if I run an app, all the prints comes to the console (eg /dev/ttyS0). If I m on any server using ssh and all apps prints comes on my putty (eg through /dev/pts/176).
Where is the code which maps fd 1 to the console in kernel? If you guys have any pointers, please share.
While opening a device (for eg /dev/something), the vfs calls that drivers, whose major and minor number matches. But in case of stdout, how vfs resolves the write to the fd 1 and send it to the corresponding console driver?
Thanks, Arun
It's in init/main.c, around line 823. "strace" is a useful tool for trying to figure out what exactly a user space process does. The man pages of various system calls (open, fork, exec, dup, etc.) may also provide valuable information. Thanks, Jonathan Neuschäfer
Ok I see your problem. vfs maintains file descriptor table for every process in the system. At every index it stores information of descriptor type and device it points to. The indexes 0,1,2 have special meaning in the context of process. 0 indicates std input, 1 indicates std output and 2 indicates std err. So whenever you use open(), socket(), or any other system call which returns descriptor (expect fopen .. libc functions) is returning the index in to this table where the info about device or operation is stored. So, whenever you use that descriptor number with other sys calls it will map in to index and extracts the information. normal calls like printf, cout uses "stdin, stdout, stderr" for printing out.
We all know that when an application writes to stdout, data ends up in the console. Because for that process index 1 maps to /dev/stdout
Okey so if I m on my development board and if I run an app, all the prints comes to the console (eg /dev/ttyS0). same as above
If I m on any server using ssh and all apps prints comes on my putty (eg through /dev/pts/176). its ssh implementation. It uses pty as stdout for printing. In such case initializing stdout = fdopen on open("/dev/stdout", "") descriptor will do your job. or use dup to set index 1 to given fd in that process
--Sri. On Mon, Apr 23, 2012 at 6:15 AM, Arun KS <getarunks@gmail.com> wrote:
Hello Guys,
We all know that when an application writes to stdout, data ends up in the console.
Okey so if I m on my development board and if I run an app, all the prints comes to the console (eg /dev/ttyS0). If I m on any server using ssh and all apps prints comes on my putty (eg through /dev/pts/176).
Where is the code which maps fd 1 to the console in kernel? If you guys have any pointers, please share.
While opening a device (for eg /dev/something), the vfs calls that drivers, whose major and minor number matches. But in case of stdout, how vfs resolves the write to the fd 1 and send it to the corresponding console driver?
Thanks, Arun
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Regards, Sri.
On Wed, Apr 25, 2012 at 02:09:24PM -0400, Sri Ram Vemulpali wrote:
We all know that when an application writes to stdout, data ends up in the console. Because for that process index 1 maps to /dev/stdout
Or rather, /dev/stdout maps to fd 1. $ ls -l /dev/stdout lrwxrwxrwx 1 root root 15 Apr 25 18:18 /dev/stdout -> /proc/self/fd/1 Thanks, Jonathan Neuschäfer
Thanks Sri Ram and Jonathan, On Wed, Apr 25, 2012 at 11:39 PM, Sri Ram Vemulpali <sri.ram.gmu06@gmail.com> wrote:
Ok I see your problem.
vfs maintains file descriptor table for every process in the system. At every index it stores information of descriptor type and device it points to. The indexes 0,1,2 have special meaning in the context of process. 0 indicates std input, 1 indicates std output and 2 indicates std err. So whenever you use open(), socket(), or any other system call which returns descriptor (expect fopen .. libc functions) is returning the index in to this table where the info about device or operation is stored. So, whenever you use that descriptor number with other sys calls it will map in to index and extracts the information.
normal calls like printf, cout uses "stdin, stdout, stderr" for printing out.
We all know that when an application writes to stdout, data ends up in the console. Because for that process index 1 maps to /dev/stdout
Okey so if I m on my development board and if I run an app, all the prints comes to the console (eg /dev/ttyS0). same as above
If I m on any server using ssh and all apps prints comes on my putty (eg through /dev/pts/176). its ssh implementation. It uses pty as stdout for printing. Okey In such case initializing stdout = fdopen on open("/dev/stdout", "") descriptor will do your job. or use dup to set index 1 to given fd in that process
Hmm... Will sshd open /dev/stdout? I think it uses /dev/ptmx and /dev/pts/* device files. Plz have a look here, http://linux.die.net/man/4/pts Arun
--Sri.
On Mon, Apr 23, 2012 at 6:15 AM, Arun KS <getarunks@gmail.com> wrote:
Hello Guys,
We all know that when an application writes to stdout, data ends up in the console.
Okey so if I m on my development board and if I run an app, all the prints comes to the console (eg /dev/ttyS0). If I m on any server using ssh and all apps prints comes on my putty (eg through /dev/pts/176).
Where is the code which maps fd 1 to the console in kernel? If you guys have any pointers, please share.
While opening a device (for eg /dev/something), the vfs calls that drivers, whose major and minor number matches. But in case of stdout, how vfs resolves the write to the fd 1 and send it to the corresponding console driver?
Thanks, Arun
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Regards, Sri.
Dude, It is more of implementation dependent. Where you want your output to display. pty is a method of sending data between two end points of communications but acts with concept of master and slave. It is written on tty driver. In case of ssh it is implementation dependent. I will leave it to you to understand the concept of vfs. Initially it is confusing, but there is lot of material online. You url is a good start. All the best. Sri. On Wed, Apr 25, 2012 at 11:56 PM, Arun KS <getarunks@gmail.com> wrote:
Thanks Sri Ram and Jonathan,
On Wed, Apr 25, 2012 at 11:39 PM, Sri Ram Vemulpali <sri.ram.gmu06@gmail.com> wrote:
Ok I see your problem.
vfs maintains file descriptor table for every process in the system. At every index it stores information of descriptor type and device it points to. The indexes 0,1,2 have special meaning in the context of process. 0 indicates std input, 1 indicates std output and 2 indicates std err. So whenever you use open(), socket(), or any other system call which returns descriptor (expect fopen .. libc functions) is returning the index in to this table where the info about device or operation is stored. So, whenever you use that descriptor number with other sys calls it will map in to index and extracts the information.
normal calls like printf, cout uses "stdin, stdout, stderr" for printing out.
We all know that when an application writes to stdout, data ends up in the console. Because for that process index 1 maps to /dev/stdout
Okey so if I m on my development board and if I run an app, all the prints comes to the console (eg /dev/ttyS0). same as above
If I m on any server using ssh and all apps prints comes on my putty (eg through /dev/pts/176). its ssh implementation. It uses pty as stdout for printing. Okey In such case initializing stdout = fdopen on open("/dev/stdout", "") descriptor will do your job. or use dup to set index 1 to given fd in that process
Hmm... Will sshd open /dev/stdout?
I think it uses /dev/ptmx and /dev/pts/* device files.
Plz have a look here, http://linux.die.net/man/4/pts
Arun
--Sri.
On Mon, Apr 23, 2012 at 6:15 AM, Arun KS <getarunks@gmail.com> wrote:
Hello Guys,
We all know that when an application writes to stdout, data ends up in the console.
Okey so if I m on my development board and if I run an app, all the prints comes to the console (eg /dev/ttyS0). If I m on any server using ssh and all apps prints comes on my putty (eg through /dev/pts/176).
Where is the code which maps fd 1 to the console in kernel? If you guys have any pointers, please share.
While opening a device (for eg /dev/something), the vfs calls that drivers, whose major and minor number matches. But in case of stdout, how vfs resolves the write to the fd 1 and send it to the corresponding console driver?
Thanks, Arun
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Regards, Sri.
-- Regards, Sri.
participants (3)
-
Arun KS -
Jonathan Neuschäfer -
Sri Ram Vemulpali