切换虚拟终端

上传人:m**** 文档编号:457749092 上传时间:2023-09-06 格式:DOCX 页数:9 大小:14.11KB
返回 下载 相关 举报
切换虚拟终端_第1页
第1页 / 共9页
切换虚拟终端_第2页
第2页 / 共9页
切换虚拟终端_第3页
第3页 / 共9页
切换虚拟终端_第4页
第4页 / 共9页
切换虚拟终端_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《切换虚拟终端》由会员分享,可在线阅读,更多相关《切换虚拟终端(9页珍藏版)》请在金锄头文库上搜索。

1、切换虚拟终端概述linux使用虚拟终端,这些虚拟终端对应/dev/tty1/dev/tty8,它们由系统初始化时打开。这个过程也在键盘的中断服务程序中完成。用户用ALT+1.8或ALT+箭头来切换终端。每个虚拟终端对应一个tty_struct和一个termios结构。Termios结构存储输入输出及控制模式,一些底层参数。Tty_struct 和终端的关系如同task_struct 和进程的关系。一个tty被打开,就对应一个tty_stract,对终端的一切处理都围绕tty_strct 进行。Termios也被tty_struct的一个指针指向。当然,tty_struct 和 termios

2、结构相对独立,tty被完全关闭时,tty_struct也就不在存在,而termios 依然存在。另:1与虚拟终端相对的是实终端。它对应/dev/tty0 或/dev/console 二者设备号均为4,0(2035)系统初始时tty的初始化分早期和晚期。早期初始化支持实终端,晚期初始化支持虚拟终端。此时/dev/tty0 或/dev/console 对应当前终端。2 伪终端正如其名,与控制台终端除了最高层的输入输出功能类似外,底层的实现大相径庭。终端切换的流程:Keyboard_interruptKey_handler(do_cons)Set_conslewant_console = nr;ma

3、rk_bh(CONSOLE_BH);Console_bhChange_consolecomplete_change_consoleUpdate_screenstatic void keyboard_interrupt(int irq, void *dev_id, struct pt_regs *regs)handle_scancode(scancode);(*key_handlertype)(keysym & 0xff, up_flag);k_hand key_handlerkeyboard.c键盘特殊输入的特殊处理函数数组。static k_hand key_handler16 = do_s

4、elf, do_fn, do_spec, do_pad, do_dead, do_cons, do_cur, do_shift,do_meta, do_ascii, do_lock, do_lowercase, do_slock,do_ignore, do_ignore, do_ignore;do_cons()改变终端的最上层函数keyboard.cstatic void do_cons(unsigned char value, char up_flag)if (up_flag)return;set_console(value);set_console()设置want_console 为欲切换

5、到的终端。设置console的bottom half 标志。kbd_kern.hextern inline void set_console(int nr)want_console = nr;mark_bh(CONSOLE_BH);console_bh()console.cstatic void console_bh(void)是否要切换consoleif (want_console = 0) if (want_console != fg_console) change_console(want_console);/* we only changed when the console had

6、already been allocated - a new console is not created in an interrupt routine */want_console = -1;if (do_poke_blanked_console) /* do not unblank for a LED change */do_poke_blanked_console = 0;poke_blanked_console();change_console()tty_io.c切换终端的实际动作。void change_console(unsigned int new_console)if (ne

7、w_console = fg_console) | (vt_dont_switch) return; if (!vc_cons_allocated(new_console)return;/*If this vt is in process mode, then we need to handshake with什么模式?在此模式下,不能直接切换,要等待! * that process before switching. Essentially, we store where that * vt wants to switch to and wait for it to tell us when

8、 its done * (via VT_RELDISP ioctl). * * We also check to see if the controlling process still exists. 控制进程 * If it doesnt, we reset this vt to auto mode and continue. 什么模式? * This is a cheap way to track process control. The worst thing * that can happen is: we send a signal to a process, it dies, a

9、nd * the switch gets lost waiting for a response; hopefully, the * user will try again, well detect the process is gone (unless * the user waits just the right amount of time :-) and revert the * vt to auto control. */VT_PROCESS模式的处理。在此模式下,不能直接切换,要等待!if (vt_consfg_console-vt_mode.mode = VT_PROCESS)/

10、* * Send the signal as privileged - kill_proc() will * tell us if the process has gone or something else * is awry */if (kill_proc(vt_consfg_console-vt_pid, vt_consfg_console-vt_mode.relsig, 1) = 0)/* * It worked. Mark the vt to switch to and * return. The process needs to send us a * VT_RELDISP ioc

11、tl to complete the switch. */vt_consfg_console-vt_newvt = new_console;return;/* * The controlling process has died, so we revert back to * normal operation. In this case, well also change back * to KD_TEXT mode. Im not sure if this is strictly correct * but it saves the agony when the X server dies

12、and the screen * remains blanked due to KD_GRAPHICS! It would be nice to do * this outside of VT_PROCESS but there is no single process * to account for and tracking tty count may be undesirable. */reset_vc(fg_console);/* * Fall through to normal (VT_AUTO) handling of the switch. */在KD_GRAPHICS+VT_A

13、UTO模式下忽略所有终端切换。if (vt_consfg_console-vc_mode = KD_GRAPHICS)return;complete_change_console(new_console);相关函数与变量判断新的虚拟终端是否存在。int vc_cons_allocated(unsigned int i)/console.creturn (i vc_mode = KD_TEXT;kbd_tablenew_console.kbdmode = VC_XLATE;vt_consnew_console-vt_mode.mode = VT_AUTO;vt_consnew_console-vt_mode.waitv = 0;vt_consnew_console-vt_mode.relsig = 0;vt_consnew_console-vt_mode.acqsig = 0;vt_consnew_console-vt_mode.frsig = 0;vt_consnew_console-vt_pid = -1;vt_consnew_console-vt_newvt = -1;reset_palette (new_console) ;compl

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > PPT模板库 > 总结/计划/报告

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号