![切换虚拟终端简介_第1页](http://file4.renrendoc.com/view/c6e6e1b1a437c2bf18655747e5886438/c6e6e1b1a437c2bf18655747e58864381.gif)
![切换虚拟终端简介_第2页](http://file4.renrendoc.com/view/c6e6e1b1a437c2bf18655747e5886438/c6e6e1b1a437c2bf18655747e58864382.gif)
![切换虚拟终端简介_第3页](http://file4.renrendoc.com/view/c6e6e1b1a437c2bf18655747e5886438/c6e6e1b1a437c2bf18655747e58864383.gif)
![切换虚拟终端简介_第4页](http://file4.renrendoc.com/view/c6e6e1b1a437c2bf18655747e5886438/c6e6e1b1a437c2bf18655747e58864384.gif)
![切换虚拟终端简介_第5页](http://file4.renrendoc.com/view/c6e6e1b1a437c2bf18655747e5886438/c6e6e1b1a437c2bf18655747e58864385.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、21/21切换虚拟终端概述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 和 ter
2、mios 结构相对独立,tty被完全关闭时,tty_struct也就不在存在,而termios 依旧存在。另:1与虚拟终端相对的是实终端。它对应/dev/tty0 或/dev/console 二者设备号均为4,0(2035)系统初始时tty的初始化分早期和晚期。早期初始化支持实终端,晚期初始化支持虚拟终端。现在/dev/tty0 或/dev/console 对应当前终端。2 伪终端正如其名,与操纵台终端除了最高层的输入输出功能类似外,底层的实现大相径庭。终端切换的流程:Keyboard_interruptKeyboard_interruptKey_handler(do_cons)Key_han
3、dler(do_cons)Set_consleSet_conslewant_console = nr;mark_bh(CONSOLE_BH);Console_bhConsole_bhChange_consoleChange_consolecomplete_change_consolecomplete_change_consoleUpdate_screenUpdate_screenstatic void keyboard_interrupt(int irq, void *dev_id, struct pt_regs *regs)handle_scancode(scancode);(*key_ha
4、ndlertype)(keysym & 0 xff, up_flag);k_hand key_handlerkeyboard.c键盘专门输入的专门处理函数数组。static k_hand key_handler16 = do_self, 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 voi
5、d do_cons(unsigned char value, char up_flag)if (up_flag)return;set_console(value);set_console()设置want_console 为欲切换到的终端。设置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_
6、console = 0) if (want_console != fg_console) change_console(want_console);/* we only changed when the console had 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_consol
7、e = 0;poke_blanked_console();change_console()tty_io.c切换终端的实际动作。void change_console(unsigned int new_console)if (new_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
8、process before switching. Essentially, we store where that * vt wants to switch to and wait for it to tell us when 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 c
9、heap way to track process control. The worst thing * that can happen is: we send a signal to a process, it dies, and * 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 rev
10、ert the * vt to auto control. */VT_PROCESS模式的处理。在此模式下,不能直接切换,要等待!if (vt_consfg_console-vt_mode.mode = VT_PROCESS)/* * 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.rel
11、sig, 1) = 0)/* * It worked. Mark the vt to switch to and * return. The process needs to send us a * VT_RELDISP ioctl 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 chang
12、e back * to KD_TEXT mode. Im not sure if this is strictly correct * but it saves the agony when the X server dies 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 und
13、esirable. */reset_vc(fg_console);/* * Fall through to normal (VT_AUTO) handling of the switch. */在KD_GRAPHICS+VT_AUTO模式下忽略所有终端切换。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_mod
14、e = 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_new
15、vt = -1;reset_palette (new_console) ;complete_change_console()切换终端的实际动作。tty_io.cvoid complete_change_console(unsigned int new_console)unsigned char old_vc_mode; if (new_console = fg_console) | (vt_dont_switch) return; if (!vc_cons_allocated(new_console) return;last_console = fg_console;/* * If were
16、switching, we could be going from KD_GRAPHICS to * KD_TEXT mode or vice versa, which means we need to blank or * unblank the screen later. */old_vc_mode = vt_consfg_console-vc_mode;依照new_console重设显示器。update_screen(new_console);/* * If this new console is under process control, send it a signal * tel
17、ling it that it has acquired. Also check if it has died and * clean up (similar to logic employed in change_console() */if (vt_consnew_console-vt_mode.mode = VT_PROCESS)/* * Send the signal as privileged - kill_proc() will * tell us if the process has gone or something else * is awry */if (kill_proc
18、(vt_consnew_console-vt_pid, vt_consnew_console-vt_mode.acqsig, 1) != 0)/* * 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 and th
19、e 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(new_console);/* * We do this here because the controlling process above may have * gone, and so th
20、ere is now a new vc_mode */if (old_vc_mode != vt_consnew_console-vc_mode)if (vt_consnew_console-vc_mode = KD_TEXT)文本模式do_unblank_screen();else 图形模式do_blank_screen(1);/* Set the colour palette for this VT */if (vt_consnew_console-vc_mode = KD_TEXT)set_palette() ;/* * Wake anyone waiting for their VT
21、to activate */vt_wake_waitactive();return;相关函数与变量#define vt_wake_waitactive() wake_up(&vt_activate_queue)update_screen()console.c重设屏幕。void update_screen(int new_console)static int lock = 0;lock保证该函数可不能被重入。if (new_console = fg_console | lock)return;if (!vc_cons_allocated(new_console) /* strange . */printk(update_screen: tty %d not alloc
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 客户经理经验交流发言稿
- 建筑工程项目经理年终总结
- 宾馆年终总结
- 酒店管理年终总结
- 公司前台年度工作计划
- 学期班务工作个人总结
- 项目前期工作计划
- 2023年宁夏回族自治区中考地理真题(原卷版)
- 华为诚信廉洁合作协议书范本
- 化妆品公司合作协议书范本
- 人工智能概论 课件 第6章 计算机视觉
- 12J201平屋面建筑构造图集(完整版)
- 招聘笔试题与参考答案(某大型央企)2024年
- 中国证监会证券市场交易结算资金监控系统证券公司接口规范
- 全国装配式建筑职业技能竞赛考试题库
- 2025届天津市部分学校高三年级八校联考英语试题含解析
- 《妊娠期病毒性肝炎临床实践指南》解读
- 水产品冷冻加工原料处理与加工技术考核试卷
- 浙教版八年级下册科学第二章 微粒的模型与符号整章思维导图
- 全新保密协议模板公安下载(2024版)
- 初一英语英语阅读理解专项训练15篇
评论
0/150
提交评论