- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我编写了一个嵌入式应用程序(vt52 终端仿真器),在基于 Linux ROM 的系统上运行,没有内置 ptys;和Unix98坏了。但由于我必须有 pty 才能使终端工作...我手动将旧式 BSD pty 编译为内核模块。但由于某些奇怪的原因,我无法使用 BSD ptys 成功发送 SIGINT (ctrl-c)...
VT52 程序是一个守护程序,而不是我想要向其发送信号的程序的父程序——但这应该不重要,不是吗?我的意思是,有一个小奴隶参与其中......
VT52 通过创建 BSD pty 对(/dev/terminal ,其中 Major=3、minor=0 权限=crwxrwxrwx,以及/dev/ptyp0 作为主要 2、次要 0 权限=crwxrwxrwx)进行通信,并打开它们进行读写。终端将击键(包括偶尔的 ctrl-c\003)发送到 ptyp0,并且还从 ptyp0 读取返回的数据。
程序作为 session 领导者启动后,通过/dev/terminal 连接到 vt52 守护进程,并获得 pty 作为控制终端。通常,我使用以下代码作为 session 领导者运行 busybox sh (?ash?) 程序:
// snippet from session.c
child=fork();
...
session=setsid();
...
// Child alone gets here.
close(0); close(1); close(2); // Close all IO to allow for a new CTTY.
open( argv[1], O_RDONLY ); // stdin
open( argv[1], O_WRONLY ); // stdout
open( argv[1], O_WRONLY ); // stderr
ioctl( 0, TIOCSCTTY, 0 ); // Set the controlling TTY based on stdin
return execvp( cmd, args ); // run whatever program the user requested.
我知道它有效,因为我在 vt52 上运行了“ps a”,并得到:
PID TTY STAT TIME COMMAND
476 ttymxc0 Ss+ 0:00 /sbin/getty -L 115200 ttymxc0 vt102
631 ? Ds+ 34:13 ./vt52 /dev/ttyGS0
706 terminal Ss 0:00 /bin/sh -i
711 terminal R+ 0:00 ps a
所以,session.c 工作了,并且 CTTY 是正确的......因此,当我发送 ctrl-c;shell 应该终止进程组/子进程——但它没有。例如,如果我运行“sleep 20”,然后按 ctrl-c,则 20 秒内没有任何反应...
我检查以确保 vt52 实际上正在将\x03 写入/dev/ptyp0,并且确实如此...
所以,然后我通过“stty -a”检查了伪终端设置:
speed 38400 baud; rows 84; columns 75;
intr - ^C; quit = "^\; erase = ^?; kill = ^U; eof = ^D;
eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; inext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff iuclc -ixany -imaxbel
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
一切看起来都不错...所以 - 我不明白为什么 SIGINT 没有被发送到 shell 的子进程。我错过了什么?
如果 shell 位于命令提示符处,并且我按 ctrl-c,它会转到下一行...尽管我不知道它是否会这样做,因为它捕获了信号,或接收了字符代码 - 而且我不知道如何弄清楚它...但无论如何,shell 都不会基于 SIGINT/control-C 进行作业控制。
帮助...:)我如何打开它?
最佳答案
线索是按 ctrl-c 在 shell 下生成一个新的提示符。我编写了一个程序来解析标准输入,并以十六进制打印出每个字符。控制 C 的代码不通过 PTY——因此 pty 毕竟生成了信号,shell 正在检测它;但子进程并没有终止。
问题在于,由于 shell 继承了其父进程的信号操作 (sigaction),因此在启动新 shell 之前必须检查或重置信号;在嵌入式设备(索尼 PRS900)上,SIGINT 和许多其他信号的默认操作已更改为 SA_IGN(忽略)。
因此,只需在 session.c 程序中添加一些代码即可将所有信号初始化为其默认操作,然后启用所有信号。这将解决问题,并且中断将正常工作。
session 日程的完整副本如下;它将创建一个新 session ,将所有信号设置为默认值并启用它们,然后它将执行您选择的程序...
// A program to create a new Linux session connecting to a specified terminal,
// and then execing a program.
// Written by Andrew Robinson of Scappoose Oregon.
// Released under (C) 2014, GPL v3
// https://www.gnu.org/copyleft/gpl.html
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
int main(int narg, char * const argv[] ) {
pid_t session;
char *const cmd = argv[2];
char *const *args = argv+2;
if (narg<3) {
fprintf(stderr,
"Usage: %s new_tty program [params]\n", argv[0] );
return 1;
}
session=fork();
if (session<0) return session;
if (session) {
int status;
printf("Session pid %d exited\n", waitpid( session, &status, 0 ) );
return status;
}
// Child falls through to here... print the sessionID.
{ // Signal handling is all to be set to defaults.
// INT should then terminate subprocesses of the shell.
sigset_t mask;
struct sigaction act;
int i;
// set all signals to the default action.
sigemptyset( &act.sa_mask );
act.sa_handler=SIG_DFL;
act.sa_flags=0;
for(i=1; i< _NSIG-1; ++i ) // Iterate over all signals.
sigaction( i, &act, NULL ); // Set action to default.
// enable all signals.
sigprocmask( SIG_SETMASK, &mask, NULL );
sigprocmask( 0,NULL,&mask );
if (!sigismember(&mask,SIGINT)) printf("SIGINT enabled\n");
}
session=setsid(); // make a session leader.
if (session<0) {
perror("bad-session:");
}
printf("%d\n", (int)session );
fflush(stdout);
close(0); close(1); close(2); // Close all IO to allow for a new CTTY.
open( argv[1], O_RDONLY ); // stdin
open( argv[1], O_WRONLY ); // stdout
open( argv[1], O_WRONLY ); // stderr
ioctl( 0, TIOCSCTTY, 0 ); // Set the controlling TTY based on stdin
return execvp( cmd, args );
}
关于Linux PTY 作为模块,但没有信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23307973/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
Linux 管道可以缓冲多少数据?这是可配置的吗? 如果管道的两端在同一个进程中,但线程不同,这会有什么不同吗? 请注意:这个“同一个进程,两个线程”的问题是理论上的边栏,真正的问题是关于缓冲的。 最
我找到了here [最后一页] 一种有趣的通过 Linux 启动 Linux 的方法。不幸的是,它只是被提及,我在网上找不到任何有用的链接。那么有人听说过一种避免引导加载程序而使用 Linux 的方法
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我试图了解 ld-linux.so 如何在 Linux 上解析对版本化符号的引用。我有以下文件: 测试.c: void f(); int main() { f(); } a.c 和 b.c:
与 RetroPie 的工作原理类似,我可以使用 Linux 应用程序作为我的桌面环境吗?我实际上并不需要像实际桌面和安装应用程序这样的东西。我只需要一种干净简单的方法来在 RaspberryPi 上
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
有什么方法可以覆盖现有的源代码,我应该用 PyQt、PyGTK、Java 等从头开始构建吗? 最佳答案 如果您指的是软件本身而不是它所连接的存储库,那么自定义应用程序的方法就是 fork 项目。据我所
我的情况是:我在一个磁盘上安装了两个 linux。我将第一个安装在/dev/sda1 中,然后在/dev/sda2 中安装第二个然后我运行第一个系统,我写了一个脚本来在第一个系统运行时更新它。
我在 i2c-0 总线上使用地址为 0x3f 的系统监视器设备。该设备在设备树中配置有 pmbus 驱动程序。 问题是,加载 linux 内核时,这个“Sysmon”设备没有供电。因此,当我在总线 0
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 11 年前。 Improve thi
我正试图在 linux 模块中分配一大块内存,而 kalloc 做不到。 我知道唯一的方法是使用 alloc_bootmem(unsigned long size) 但我只能从 linux 内核而不是
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我有 .sh 文件来运行应用程序。在该文件中,我想动态设置服务器名称,而不是每次都配置。 我尝试了以下方法,它在 CentOS 中运行良好。 nohup /voip/java/jdk1.8.0_71/
我是在 Linux 上开发嵌入式 C++ 程序的新手。我有我的 Debian 操作系统,我在其中开发和编译了我的 C++ 项目(一个简单的控制台进程)。 我想将我的应用程序放到另一个 Debian 操
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
我使用4.19.78版本的稳定内核,我想找到带有企鹅二进制数据的C数组。系统启动时显示。我需要在哪里搜索该内容? 我在 include/linux/linux_logo.h 文件中只找到了一些 Log
我知道可以使用 gdb 的服务器模式远程调试代码,我知道可以调试针对另一种架构交叉编译的代码,但是是否可以更进一步,从远程调试 Linux 应用程序OS X 使用 gdbserver? 最佳答案 当然
是否有任何可能的方法来运行在另一个 Linux 上编译的二进制文件?我知道当然最简单的是在另一台机器上重建它,但假设我们唯一能得到的是一个二进制文件,那么这可能与否? (我知道这可能并不容易,但我只是
我是一名优秀的程序员,十分优秀!