版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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/ttyO或/dev/c on sole二者设备号均为4,0(2. 0. 35)系统初始时tty的初始化分早期和晚期。早期初始化支持实终端,晚期初始化 支持虚拟终端。此时 /dev/tty0或/dev/console对应当前终端。2伪终端正如其名,与控制台终端除了最高层的输入输出功能类似外,底层的实现大相径庭。终端切换的流程:Keyboard, in terruptKey_ha ndler(do_c ons)Set_c on slewant_con sole
3、 = nr; mark_bh(CONSOLE_BH);static void keyboard_ in terrupt(i nt irq, void *dev_id, struct pt_regs *regs) han dle_sca ncode(sca ncode);(*key_handlertype)(keysym & Oxff, up_flag);k_hand key_handler|keyboard.c键盘特殊输入的特殊处理函数数组。static k_ha nd key_ha ndler16 = do_self, do_fn, do_spec, do_pad, do_dead, do_
4、c ons, do_cur, do_shift, do_meta, do_ascii, do_lock, do_lowercase, do_slock.do_ig nore, do_ig nore, do_ig nore ;do_cons ()改变终端的最上层函数keyboard.cstatic void do_c ons(un sig ned char value, char up_flag) if (up_flag)return;set_c on sole(value);set_console()设置wa nt_con sole为欲切换到的终端。 设置con sole的bottom hal
5、f标志。kbd_ker n.hextern in li ne void set_c on sole(i nt nr)want_con sole = nr;mark_bh(CONSOLE_BH);console_bh()con sole.cstatic void con sole_bh(void)是否要切换con soleif (want_console = 0) if (want_console != fg_console) change_console(want_console);/* we only cha nged whe n the con sole had already bee n
6、 allocated - a new con sole is not created in an in terrupt routi ne */want_con sole = -1;if (do_poke_bla nked_c on sole) /* do not un bla nk for a LED cha nge */ do_poke_bla nked_c on sole = 0; poke_bla nked_c on sole();change_console ()tty_io.c切换终端的实际动作。void cha nge_c on sole( un sig ned int n ew_
7、c on sole)if (n ew_c on sole = fg_con sole) | (vt_do nt_switch) return;if (!vc_c on s_allocated( new_c on sole)return;/*If this vt is in process mode, the n we n eed to han dshake with什么模式?在此模式下,不能直接切换,要等待!* that process before switch ing. Esse ntially, we store where that* vt wants to switch to and
8、 wait for it to tell us when its done* (via VT_RELDISP ioctl).* We also check to see if the con trolli ng process still exists.控制进程* If it does nt, we reset this vt to auto mode and continue.AAAAAAAAAA什么模式?* This is a cheap way to track process con trol. The worst thi ng* that can happe n is: we sen
9、d a sig nal to a process, it dies, and* the switch gets lost wait ing for a resp on se; hopefully, the* user will try aga in, well detect the process is gone (uni ess* the user waits just the right amount of time :-) and revert the* vt to auto con trol.*/VT_PROCESS模式的处理。在此模式下,不能直接切换,要等待!if (vt_co ns
10、fg_co nsole-vt_mode.mode = VT_PROCESS)/* Send the sig nal as privileged - kill_proc() will* tell us if the process has gone or someth ing else* is awry*/if (kill_proc(vt_c on sfg_c on sole-vt_pid,vt_con sfg_c on sole-vt_mode.relsig, 1) = 0)/* It worked. Mark the vt to switch to and* retur n. The pro
11、cess n eeds to send us a* VT_RELDISP ioctl to complete the switch. */vt_con sfg_c on sole-vt_ newvt = n ew_c on sole; return; /* The con trolli ng process has died, so we revert back to* no rmal operati on. In this case, well also cha nge back* to KD_TEXT mode. Im not sure if this is strictly correc
12、t* but it saves the ago ny whe n the X server dies and the scree n* remai ns bla nked due to KD_GRAPHICS! It would be nice to do* this outside of VT_PROCESS but there is no si ngle process* to acco unt for and track ing tty count may be un desirable.*/reset_vc(fg_c on sole);/* Fall through to normal
13、 (VT_AUTO) handling of the switch.*/在KD_GRAPHICS+VT_AUTO模式下忽略所有终端切换。if (vt_con sfg_co nsole-vc_mode = KD_GRAPHICS)return;complete_cha nge_c on sole( new_c on sole);相关函数与变量判断新的虚拟终端是否存在。int vc_c on s_allocated( un sig ned in t i)/c on sole.creturn (i vc_mode = KD_TEXT; kbd_table new_co nsole.kbdmode =
14、 VC_XLATE;vt_c onsn ew_c on sole-vt_mode.mode = VT_AUTO;vt_c onsn ew_c on sole-vt_mode.waitv = 0;vt_c onsn ew_c on sole-vt_mode.relsig = 0;vt_c onsn ew_c on sole-vt_mode.acqsig = 0;vt_c onsn ew_c on sole-vt_mode.frsig = 0;vt_c onsn ew_c on sole-vt_pid = -1;vt_c onsn ew_c on sole-vt_ newvt = -1; rese
15、t_palette (n ew_c on sole);complete_change_console()切换终端的实际动作。tty_io.cvoid complete_cha nge_c on sole( un sig ned int n ew_c on sole)un sig ned char old_vc_mode;if (n ew_c on sole = fg_con sole) | (vt_do nt_switch)return;if (!vc_c on s_allocated( new_c on sole)return;l ast_c on sole = fg_con sole;/*
16、 If were switchi ng, we could be goi ng from KD_GRAPHICS to* KD_TEXT mode or vice versa, which means we n eed to bla nk or* un bla nk the scree n later.*/old_vc_mode = vt_con sfg_c on sole-vc_mode; 根据new_console重设显示器。update_scree n(n ew_c on sole);/* If this new con sole is un der process con trol,
17、send it a sig nal* telling it that it has acquired. Also check if it has died and* clea n up (similar to logic employed in cha nge_c on sole()*/if (V_con s new_co nsole-V_mode.mode = VT_PROCESS)/* Send the signal as privileged - kill_proc() will* tell us if the process has gone or someth ing else* i
18、s awry*/if (kill_proc(vt_c onsn ew_c on sole-vt_pid,V_consn ew_c on sole-V_mode.acqsig,1) != 0)/* The con trolli ng process has died, so we revert back to* no rmal operati on. In this case, well also cha nge back* to KD_TEXT mode. Im not sure if this is strictly correct* but it saves the ago ny whe
19、n the X server dies and the scree n* remai ns bla nked due to KD_GRAPHICS! It would be nice to do* this outside of VT_PROCESS but there is no si ngle process* to acco unt for and track ing tty count may be un desirable.*/reset_vc( new_c on sole);/* We do this here because the con troll ing process a
20、bove may have* gone, and so there is now a new vc_mode*/if (old_vc_mode != vt_consn ew_c on sole-vc_mode)if (vt_c onsn ew_c on sole-vc_mode = KD_TEXT)文本模式do_un bla nk_scree n();else图形模式do_bla nk_scree n(1);/* Set the colour palette for this VT */if (vt_c onsn ew_c on sole-vc_mode = KD_TEXT)set_palet
21、te();/* Wake anyone wait ing for their VT to activate*/vt_wake_waitactive();return;相关函数与变量#defi ne vt_wake_waitactive() wake_up(&vt_activate_queue)update_screen ()con sole.c重设屏幕。void update_scree n(i nt n ew_c on sole)static int lock = 0;lock保证该函数不会被重入。if (n ew_c on sole = fg_con sole | lock)return;if (!vc_c on s_allocated( new_c on sole) /* stra nge . */prin tk(update_scree n: tty %d not allocated ?n, n ew_c on sole+1);return;l
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年南通科技职业学院单招职业技能测试题库附答案详解(预热题)
- 2026年克孜勒苏职业技术学院单招职业技能考试题库带答案详解(a卷)
- 2026年厦门华天涉外职业技术学院单招职业技能考试题库带答案详解(基础题)
- 2026年佳木斯职业学院单招职业适应性测试题库及完整答案详解1套
- 2026年内蒙古商贸职业学院单招职业技能测试题库附参考答案详解(考试直接用)
- 2026年南京旅游职业学院单招职业技能考试题库带答案详解(预热题)
- 2026年南昌健康职业技术学院单招职业倾向性测试题库及1套完整答案详解
- 2023年带GP-IB总线接口的各类台式仪器行业分析报告及未来五至十年行业发展报告
- 陕西省西安市第六十六中学2026届高三英语试题下学期第四次月考试题含解析
- 青海省黄南市重点中学2026年下学期普通高中期末考试试卷高三物理试题含解析
- 2025-2026学年高一上学期期末英语模拟卷(译林版)(解析版)
- 基于人工智能的大学语文教学数字化转型与挑战
- 甲状腺相关眼病护理查房
- 2025年宁夏回族自治区学校教师队伍“十五五”发展规划
- 2026中国铁塔股份有限公司校园招聘备考考试试题及答案解析
- 业务流程优化实施指南
- 2025年美容整容医师认证考试试题及答案
- 人流后超声诊断规范与应用
- 黑龙江流浪犬管理办法
- 入党申请书专用纸-A4单面打印
- 2025企业年会总结大会跨越新起点模板
评论
0/150
提交评论