版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、切換虛擬終端概述linux 使用虛擬終端,這些虛擬終端對應(yīng) /dev/tty1/dev/tty8, 它們由系統(tǒng)初始化時打開。 這個過程也在鍵盤的中斷服務(wù)程序中完成。用戶用ALT+1.8 或 ALT+ 箭頭來切換終端。每個虛擬終端對應(yīng)一個 tty_struct 和一個 termios 結(jié)構(gòu)。 Termios 結(jié)構(gòu)存儲輸入輸出及控制模式, 一些底層參數(shù)。 Tty_struct 和終端的關(guān)系如同 task_struct 和進(jìn)程的關(guān)系。一個 tty 被打開, 就對應(yīng)一個tty_stract,對終端的一切處理都圍繞tty_strct進(jìn)行。Termios也被tty_struct的一個指針指向。當(dāng)然, tt
2、y_struct 和 termios 結(jié)構(gòu)相對獨(dú)立, tty 被完全關(guān)閉時, tty_struct 也就不 在存在,而 termios 依然存在。另:1 與虛擬終端相對的是實(shí)終端。它對應(yīng)/dev/tty0 或 /dev/console 二者設(shè)備號均為4,0(2 0 35)系統(tǒng)初始時 tty 的初始化分早期和晚期。早期初始化支持實(shí)終端,晚期初始化 支持虛擬終端。此時 /dev/tty0 或 /dev/console 對應(yīng)當(dāng)前終端。底層的實(shí)現(xiàn)大相2 偽終端正如其名, 與控制臺終端除了最高層的輸入輸出功能類似外, 徑庭。終端切換的流程:want_con sole = nr;mark_bh(CONSO
3、LE_BH);static void keyboard, in terr up t(i nt irq, void *dev_id, struct p t_regs *regs)han dle_sca ncode(sca ncode);(*key_ha ndlert yp e)(keysym & Oxff, up_flag);k_hand key_handlerkeyboard.c鍵盤特殊輸入的特殊處理函數(shù)數(shù)組。static k_ha nd key_ha ndler16 = do_self, do_fn, do_s pec, do_p ad, do_dead, do_c ons, do_cur,
4、 do_shift, do_meta, do_ascii, do_lock, do_lowercase, do_slock, do_ignore, do_ignore, do_ignore;do_cons()改變終端的最上層函數(shù)keyboard.cstatic void do_cons(unsigned char value, char up_flag) if (up_flag) return;set_console(value);set_console()設(shè)置 want_console 為欲切換到的終端。 設(shè)置 console 的 bottom half 標(biāo)志。kbd_kern.hexter
5、n 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 already been allocated - a new console i
6、s 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í)際動作。void change_console(unsigned int new_console) if (new_console = fg_console) | (vt_dont_s
7、witch) 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 its done* (via VT_RELDISP ioctl).* We
8、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, it dies, and* the switch gets lost waiting for
9、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) /* Send the signal as privileged - kill_
10、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 ioctl to complete the switch.*/vt_consfg_console-vt_n
11、ewvt = 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 screen* remains blanked due to KD_GRAPHICS! It
12、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 模式下忽略所有終端切換。 if (vt_consfg_console-vc_mode = KD_GRAPHI
13、CS) 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 = 0; vt_consnew_console-vt_mode.relsig
14、 = 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í)際動作。tty_io.cvoid complete_change_console(unsigned int new_console) unsigned char old_vc_mo
15、de;if (new_console = fg_console) | (vt_dont_switch) return;if (!vc_cons_allocated(new_console)return;last_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_
16、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_consnew_console-vt_mode.mode = VT_PRO
17、CESS) /* 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 operation. In this case, well a
18、lso 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 and tracking tty count may b
19、e 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_blank_screen(1);/* Set the co
20、lour 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ù)不會被重入。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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 城市綠化合同管理辦法
- 宗教藝術(shù)博物館管理辦法
- 一站式工程維護(hù)服務(wù)承諾書
- 車輛限號管理辦法
- 美容院實(shí)習(xí)生轉(zhuǎn)正合同
- 城市供電設(shè)施拆遷電力保障
- 生態(tài)養(yǎng)殖場養(yǎng)豬場租賃
- 城市綠化箱涵施工合同
- 產(chǎn)品售后服務(wù)承諾書協(xié)議書
- 建筑照明工程合同
- 走中國工業(yè)化道路的思想及成就
- ESTIC-AU40使用說明書(中文100版)(共138頁)
- 河北省2012土建定額說明及計算規(guī)則(含定額總說明)解讀
- Prolog語言(耐心看完-你就入門了)
- 保霸線外加電流深井陽極地床陰極保護(hù)工程施工方案
- 藍(lán)色商務(wù)大氣感恩同行集團(tuán)公司20周年慶典PPT模板
- 恒溫箱PLC控制系統(tǒng)畢業(yè)設(shè)計
- 雍琦版 《法律邏輯學(xué)》課后習(xí)題答案
- 176033山西《裝飾工程預(yù)算定額》定額說明及計算規(guī)則
- 新技術(shù)、新材料、新工藝”試點(diǎn)輸電線路建設(shè)的通知國家電網(wǎng)
- 水泵試運(yùn)轉(zhuǎn)記錄表
評論
0/150
提交評論