终端串口“ctrl+C“失效问题的解决(/bin/sh: can‘t access tty; job control turned off)

1、问题现象

/bin/sh: can't access tty; job control turned off

(1)在内核的启动打印中,在进入串口前会打印出上面信息,显示进入控制台失败;
(2)在串口终端中,在调用可执行程序或者ping命令时,“ctrl+C”失效,导致不能退出,只能重启设备;

2、问题的解决过程

2.1、串口终端的开启

# Example of how to put a getty on a serial line (for a terminal)
::respawn:/bin/sh 

(1)串口终端程序是"/bin/sh"或者“/bin/dash”,在inittab文件中被调用;
(2)inittab文件被busybox解析,上面是我的设备里inittab文件中对“/bin/sh”的调用;

2.2、了解inittab文件

参考博客:https://blog.csdn.net/weixin_42031299/article/details/120107948;

2.3、查看busybox中inittab文件的说明

"Example /etc/inittab file:\n" \
"\n" \
"	# This is run first except when booting in single-user mode\n" \
"	#\n" \
"	::sysinit:/etc/init.d/rcS\n" \
"	\n" \
"	# /bin/sh invocations on selected ttys\n" \
"	#\n" \
"	# Start an \"askfirst\" shell on the console (whatever that may be)\n" \
"	::askfirst:-/bin/sh\n" \
"	# Start an \"askfirst\" shell on /dev/tty2-4\n" \
"	tty2::askfirst:-/bin/sh\n" \
"	tty3::askfirst:-/bin/sh\n" \
"	tty4::askfirst:-/bin/sh\n" \
"	\n" \
"	# /sbin/getty invocations for selected ttys\n" \
"	#\n" \
"	tty4::respawn:/sbin/getty 38400 tty4\n" \
"	tty5::respawn:/sbin/getty 38400 tty5\n" \
"	\n" \
"	\n" \
"	# Example of how to put a getty on a serial line (for a terminal)\n" \
"	#\n" \
"	#::respawn:/sbin/getty -L ttyS0 9600 vt100\n" \
"	#::respawn:/sbin/getty -L ttyS1 9600 vt100\n" \
"	#\n" \
"	# Example how to put a getty on a modem line\n" \
"	#::respawn:/sbin/getty 57600 ttyS2\n" \
"	\n" \
"	# Stuff to do when restarting the init process\n" \
"	::restart:/sbin/init\n" \
"	\n" \
"	# Stuff to do before rebooting\n" \
"	::ctrlaltdel:/sbin/reboot\n" \
"	::shutdown:/bin/umount -a -r\n" \
"	::shutdown:/sbin/swapoff -a\n"

(1)在busybox源码的include/usage.h文件中,有对inittab文件的说明,其中的示例inittab文件就有串口终端的调用;
(2)首先我很明确在串口终端中是可以支持"ctrl+C"信号的接收,经过对比busybox中示例inittab文件和设备正在使用的inittab文件,发现busybox中在调用串口终端程序时添加了’-'符号;

2.4、修改inittab文件

# Example of how to put a getty on a serial line (for a terminal)
::respawn:-/bin/sh 

在根文件系统中,将inittab文件中调用串口终端程序时添加’-'符号,重新烧录根文件系统,问题解决,串口终端的“ctrl+C”生效;

3、‘-’符号的作用

(1)调用串口终端程序时添加‘-’符号,则终端是"交互的",可以接收“ctrl+C”信号;
(2)具体为什么添加‘-’符号程序就变成“交互式”,以及“交互式”和“非交互式”的区别,我没有再深入去了解,可以看看busybox中是否对‘-’符号做了解析,或者继续百度查一下;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

正在起飞的蜗牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值