最近在公司弄 embedded linux 的東西,boot 完 kernel 進到 busybox 後, 發現 ctrl+c 竟然沒有作用(沒有 ctrl+c真的很不方便),我們可以看一下當ctrl+c 按下所經過的路徑driver/char/n_tty.c :n_tty_receive_buf() --> n_tty_receive_break() --> isig(SIGINT,tty,1)-->kernel/signal.c :kill_pgrp(tty->pgrp, SIGINT, 1)-->kill_pgrp_info(SIGINT, __si_special(priv), pid)-->最後會中斷每個 group number 為 tty->pgrp的task,只要process具有相同的group id不管 background / foreground 都會被 kill 掉,ctrl+c是傳送到 /dev/ttyS0 driver 的,在原本的 root file system 並沒有 ttyS0 這個 device node,使用的是 /dev/console 這個 device後來在 busybox 網站 FAQ 查到Job control will be turned off since your shell can not obtain a controlling terminal. If you want your shell to run on /dev/console, then you can hack your kernel (if you are into that sortof thing) by changing drivers/char/tty_io.c to change the lines where it sets "noctty = 1;" to instead set it to "0".解決方法如下第一種方法1. 在 dev 目錄下建立 ttyS0 device node, 將 console link 到 ttyS0#mknod --mode 666 ttyS0 c 4 64#ln -s ttyS0 console2. 修改 /etc/inittab#vi /etc/inittabconsole::sysinit:-/etc/rcSttyS0::respawn:-/bin/sh第二種方法Hack kernel修改 drivers/char/tty_io.c 將 noctty = 1 的地方改為 noctty = 0然後 /etc/inittab 就可以寫成console::sysinit:-/etc/rcSconsole::respawn:-/bin/sh重新製作 root file system 測試果然 ok了不過 busybox 的建議是在 real console 下 run shell ....
10-25 14:00
查看更多