Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9149407
  • 博文数量: 1727
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 19860
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1727)

文章存档

2024年(2)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: LINUX

2012-03-26 16:31:39

最近在公司弄 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. This typically happens when you run your shell on /dev/console. The kernel will not provide a controlling terminal on the /dev/console device. Your should run your shell on a normal tty such as tty1 or ttyS0 and everything will work perfectly. If you REALLY 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". I recommend you instead run your shell on a real console...

解決方法如下

第一種方法
1. 在 dev 目錄下建立 ttyS0 device node, 將 console link 到 ttyS0

#mknod --mode 666 ttyS0 c 4 64
#ln -s ttyS0 console


2. 修改 /etc/inittab

#vi /etc/inittab
console::sysinit:-/etc/rcS
ttyS0::respawn:-/bin/sh


第二種方法
Hack kernel
修改 drivers/char/tty_io.c
將 noctty = 1 的地方改為 noctty = 0
然後 /etc/inittab 就可以寫成
console::sysinit:-/etc/rcS
console::respawn:-/bin/sh

重新製作 root file system 測試果然 ok了

不過 busybox 的建議是在 real console 下 run shell ....
阅读(3220) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~