admin 管理员组

文章数量: 887007

终端串口“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文件

参考博客:;

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中是否对‘-’符号做了解析,或者继续百度查一下;

本文标签: 终端串口“ctrlC“失效问题的解决(binsh cant access tty job control turned off)