区分/dev/tty、/dev/console、/dev/pts、/dev/ttyn

Article Directory

When I was creating rootfs, I encountered the device /dev/pts, because rootfs needs to be able to log in through telnet in the end. So understand the following devices under the /dev/ directory.

Usually the console (console) we see under linux is completed by several devices. They are /dev/ttyN (where tty0 is /dev/console, tty1, tty2 are different virtual terminals (virtual console)). Usually use the hotkey alt+Fn to switch between these virtual terminals. All these tty devices are corresponded by linux/drivers/char/console.c and vt.c.

/dev/ptsIt is the directory where the console device files created after remote login (telnet, ssh, etc.) are located. Since there may be thousands of users logging in, it /dev/ptsis actually dynamically generated, unlike other device files that are hard disk nodes that have been generated when the system is built (if devfs is not used)

I do not know if it is dynamically established? But when making the file system, you need to manually create the /dev/pts device directory.

mkdir -p /dev/pts
mkdir -p /dev/shm
/bin/mount -n -t devpts none /dev/pts -o mode=0622
/bin/mount -n -t tmpfs tmpfs /dev/shm

The code comes from the rootfs of mini2440.

The first user logs in, the device file of the console is /dev/pts/0, the second is /dev/pts/1, and so on. The 0, 1, 2, and 3 here are not specific standard input or output, but the entire console. You can try echo "aaaaaa" > / dev/pts0, 1, 2....

/dev/ttyRefers to the current terminal, and the content output here will only be displayed on the current working terminal display

/dev/consoleis tty0

/dev/ptsIt is the directory where the console device files created after remote login (telnet, ssh, etc.) are located

/dev/nullIs an empty device, also known as "bit bucket bit bucket". All output written to this device will be discarded, and if you read /dev/null, you will immediately return with an end-of-file flag.

In the shell, it's common to redirect unwanted stuff into /dev/null.

Guess you like

Origin blog.csdn.net/mayue_web/article/details/129896989