切換虛擬終端簡(jiǎn)介_(kāi)第1頁(yè)
切換虛擬終端簡(jiǎn)介_(kāi)第2頁(yè)
切換虛擬終端簡(jiǎn)介_(kāi)第3頁(yè)
切換虛擬終端簡(jiǎn)介_(kāi)第4頁(yè)
切換虛擬終端簡(jiǎn)介_(kāi)第5頁(yè)
已閱讀5頁(yè),還剩2頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、切換虛擬終端概述linux 使用虛擬終端,這些虛擬終端對(duì)應(yīng) /dev/tty1/dev/tty8, 它們由系統(tǒng)初始化時(shí)打開(kāi)。 這個(gè)過(guò)程也在鍵盤(pán)的中斷服務(wù)程序中完成。用戶(hù)用ALT+1.8 或 ALT+ 箭頭來(lái)切換終端。每個(gè)虛擬終端對(duì)應(yīng)一個(gè) tty_struct 和一個(gè) termios 結(jié)構(gòu)。 Termios 結(jié)構(gòu)存儲(chǔ)輸入輸出及控制模式, 一些底層參數(shù)。 Tty_struct 和終端的關(guān)系如同 task_struct 和進(jìn)程的關(guān)系。一個(gè) tty 被打開(kāi), 就對(duì)應(yīng)一個(gè)tty_stract,對(duì)終端的一切處理都圍繞tty_strct進(jìn)行。Termios也被tty_struct的一個(gè)指針指向。當(dāng)然, tt

2、y_struct 和 termios 結(jié)構(gòu)相對(duì)獨(dú)立, tty 被完全關(guān)閉時(shí), tty_struct 也就不 在存在,而 termios 依然存在。另:1 與虛擬終端相對(duì)的是實(shí)終端。它對(duì)應(yīng)/dev/tty0 或 /dev/console 二者設(shè)備號(hào)均為4,0(2 0 35)系統(tǒng)初始時(shí) tty 的初始化分早期和晚期。早期初始化支持實(shí)終端,晚期初始化 支持虛擬終端。此時(shí) /dev/tty0 或 /dev/console 對(duì)應(yīng)當(dāng)前終端。2 偽終端正如其名, 與控制臺(tái)終端除了最高層的輸入輸出功能類(lèi)似外, 底層的實(shí)現(xiàn)大相 徑庭。終端切換的流程:Keyboardn terruptKey_ha ndler(d

3、o_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鍵盤(pán)特殊輸入的特殊處理函數(shù)數(shù)組。static k_ha nd key_ha ndler16 = do_self, do_f

4、n, 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()改變終端的最上層函數(shù) keyboard.c static void do_cons(unsigned char value, char up_flag) if (up_flag) return;set_console(value);set_console()設(shè)置 want_console 為欲切換到

5、的終端。設(shè)置 console 的 bottom half 標(biāo)志。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 consol

6、e 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 切換終端的實(shí)際動(dòng)作。 void change_console(unsigned int new_cons

7、ole) 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* vt wants to switch to and wait for it to tell

8、 us when its done* (via VT_RELDISP ioctl).* We also check to see if the controlling process still exists.控制進(jìn)程* 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, i

9、t 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 revert the* vt to auto control.*/VT_PROCESS 模式的處理。在此模式下,不能直接切換,要等待!if (vt_consfg_console-vt_mode.mode = VT_PROC

10、ESS)/* Send the signal as privileged - kill_proc() will* tell us if the process has gone or something else* is awryif (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

11、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 and the sc

12、reen* 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_AUTO 模式下忽略所有終端切換。

13、if (vt_consfg_console-vc_mode = KD_GRAPHICS)return;complete_change_console(new_console);相關(guān)函數(shù)與變量判斷新的虛擬終端是否存在。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

14、 = 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) ;complete_change_console ()切換終端的實(shí)際動(dòng)作。tty_io.cvoid complete_change_console(unsigned i

15、nt new_console)unsigned char old_vc_mode;if (new_console = fg_console) | (vt_dont_switch) return;if (!vc_cons_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

16、screen later.*/old_vc_mode = vt_consfg_console-vc_mode;根據(jù) new_console 重設(shè)顯示器。update_screen(new_console);/* If this new console is under process control, send it a signal* telling it that it has acquired. Also check if it has died and* clean up (similar to logic employed in change_console()if (vt_cons

17、new_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_consnew_console-vt_pid,vt_consnew_console-vt_mode.acqsig,1) != 0)/* The controlling process has died, so we revert back to* normal o

18、peration. 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 single process* to account for

19、 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 (vt_consnew_console-vc_mode = KD_TEXT)文本模式do_unblank_screen();else圖形模式do_bla

20、nk_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; 相關(guān)函數(shù)與變量 #define vt_wake_waitactive() wake_up(&vt_activate_queue)update_screen ()console.c 重設(shè)屏幕。void update_screen(int new_console)static int lock = 0; lock 保證該函數(shù)不會(huì)被重入。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);

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論