ansole终端链接linux,切换虚拟终端

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

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的一个指针指向。当然, tt。

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

3、r(do_c ons)Set_c on slewant_con sole = 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_handlerkeyboard.c键盘特殊输入的特殊处理函数数组。static k_ha nd key_ha ndler16 = do_self, d。

4、o_fn, do_spec, do_pad, do_dead, do_c ons, do_cur, do_shift, do_meta, do_ascii, do_lock, do_lowercase, do_slock,do_ignore, do_ignore, do_ignore ;do_cons()改变终端的最上层函数 keyboard.c static 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 con。

6、sole 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_console = 0;poke_blanked_console();change_console ()tty_io.c 切换终端的实际动作。 void change_console(unsigned int new_c。

7、onsole) 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 process before switching. Essentially, we store where that* (via VT_RELDISP ioctl).* We also check to 。

8、see if the controlling process still exists.控制进程* If it doesnt, we reset this vt to auto mode and continue.AAAAAAAAAA什么模式?* 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, and* the switch gets lost waiting for a response; hop。

9、efully, 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)/* Send the signal as privileged - kill_proc() will* is a。

10、wry*/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 ioctl to complete the switch.*/vt_consfg_console-vt_newvt = new_console; return;/* The controlling process has died, so w。

11、e 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 the screen* remains blanked due to KD_GRAPHICS! It would be nice to do* this outside of VT_PROCESS but there is no sing。

12、le 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_AUTO 模式下忽略所有终端切换。 if (vt_consfg_console-vc_mode = KD_GRAPHICS) return;complete_change_console(new_console); 相关函数与变量判断新的虚拟终端是否存在。i。

13、nt 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。

14、.frsig = 0; vt_consnew_console-vt_pid = -1; vt_consnew_console-vt_newvt = -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_。

15、allocated(new_console)return;l ast_console = fg_console;/* If were 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 t。

16、his new console is under process control, send it a signal* 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* is awry*/if (kill_proc(vt_consnew_console-vt_pid,vt_consnew_console-vt_mode.acqsi。

17、g,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 the screen* remains blanked due to KD_GRAPHICS! It would be nice to 。

18、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 there is now a new vc_mode*/if (old_vc_mode != vt_consnew_console-vc_mode)if。

19、 (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 to activate*/vt_wake_waitactive();return; 相关函数与变量 #define vt_wake_waitactive()。

20、 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 allocated ?n, new_console+1); return; loc。

21、k = 1; 清除屏幕被选择部分。clear_selection();if (!console_blanked) get_scrmem(fg_console);else console_blanked = -1;/* no longer of the form console+1 */f g_console = new_console; /* this is the only (nonzero) assignment to fg_console */ /* consequently, fg_console will always be allocated */ set_scrmem(fg_co。

22、nsole, 0); /vga.c set_origin(fg_console);set_cursor(fg_console);set_leds();recompute k_down and shift_state from key_down */ compute_shiftstate(); / linux/drivers/char/keyboard.c lock = 0; 相关函数与变量clear_selection(void) /selection.c highlight_pointer(-1); /* hide the pointer */ if (sel_start != -1) highlight(sel_start, sel_end); sel_start = -1;int console_blanked = 0; /console.c。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值