/dev/tty node

tty

  3.控制终端(/dev/tty)

  如果当前进程有控制终端(Controlling Terminal)的话,那么/dev/tty就是当前进程的控制终端的设备特殊文件。
  可以使用命令”ps –ax”来查看进程与哪个控制终端相连。对于你登录的shell,/dev/tty就是你使用的终端,
  设备号是(5,0)。
  使用命令 ”tty”可以查看它具体对应哪个实际终端设备。/dev/tty有些类似于到实际所使用终端设备的一个联接。

 

/ dev / tty0是当前(前景)虚拟控制台的别名,因此它可以是tty1,tty2等。注意,ttyS0不是别名。这是第一个串行端口。

/ dev / console是系统控制台,它默认指向/ dev / tty0。可以是ttyn,ttySn,ttyUSBn,lpn等。

 

 

/dev/tty1-tty63在如下函数里创建,MAX_NR_CONSOLES值定义为64. /dev/tty0表示当前(前景)虚拟控制台的别名,tty1-tty63是虚拟控制台:

drivers/tty/vt/vt.c

#define MAX_NR_CONSOLES 63 /* serial lines start at 64 */

int __init vty_init(const struct file_operations *console_fops)
{
    cdev_init(&vc0_cdev, console_fops);
    if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
        register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
        panic("Couldn't register /dev/tty0 driver\n");
    tty0dev = device_create_with_groups(tty_class, NULL,
                        MKDEV(TTY_MAJOR, 0), NULL,
                        vt_dev_groups, "tty0");
    if (IS_ERR(tty0dev))
        tty0dev = NULL;

    vcs_init();

    console_driver = alloc_tty_driver(MAX_NR_CONSOLES);
    if (!console_driver)
        panic("Couldn't allocate console driver\n");

    console_driver->name = "tty";
    console_driver->name_base = 1;
    console_driver->major = TTY_MAJOR;
    console_driver->minor_start = 1;
    console_driver->type = TTY_DRIVER_TYPE_CONSOLE;
    console_driver->init_termios = tty_std_termios;
    if (default_utf8)
        console_driver->init_termios.c_iflag |= IUTF8;
    console_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS;
    tty_set_operations(console_driver, &con_ops);
    if (tty_register_driver(console_driver))
        panic("Couldn't register console driver\n");
    kbd_init();
    console_map_init();
#ifdef CONFIG_MDA_CONSOLE
    mda_console_init();
#endif
    return 0;
}

 

如果需要修改tty的数量,修改上述MAX_NR_CONSOLES就行。

 

同理vcs等多余的设备也可以这么删除

 

posted @ 2021-08-06 14:43  aspirs  阅读(296)  评论(0编辑  收藏  举报