为什么我无法检索从反引号内部暂停的程序?
我创建了一个程序,该程序使用参数列表并将其放在新tty的网格中,我可以在其中移动并从中选择所需的内容.
I created a program that takes a list of arguments and put them in a grid on a new tty where I can move around and select from it what I want.
当我运行程序时没有这样的反引号...
When I run the program without backticks like this...
$> ./ft_select arg_1 arg_2 ... arg_N
打开一个新的tty并显示一个网格...
A new tty is opened and a grid is shown...
arg_1 arg_2 arg_3
arg_4 arg_5 arg_6
arg_7 ... arg_N
我按 ctrl + z ,程序被挂起没有问题,并且fg
命令将其放回.
I hit ctrl+z and the program gets suspended with no problem and fg
command puts it back.
我的问题是,当我在反引号之间放置命令并尝试挂起它时,它卡住了而没有给出提示.
My problem is that when I put the command between backticks and I try to suspend it, it get stuck without giving the prompt back.
我不得不提到我将网格的所有内容写在/dev/tty
I have to mention that I write all the content of the grid on /dev/tty
您可以在下面的代码中找到执行信号处理的功能.
You can find in the code below the function that does the signal handling.
23 void signalhandler(int sig)
24 {
25 // struct winsize ws;
26
27 if (sig == SIGWINCH)
28 {
29 // ioctl(g_data->tty, TIOCGWINSZ, &ws);
30 update_data(g_data);
31 print_args(g_data);
32 update_cursor(g_data, 1);
33 }
34 else if (sig == SIGTSTP)
35 {
36 signal(SIGTSTP, SIG_DFL);
37 enable_cap("te");
38 modify_main_caps(SET, g_data->tty);
39 ioctl(g_data->tty, TIOCSTI, "\032");
40 }
41 else if (sig == SIGCONT)
42 {
43 signal(SIGTSTP, signalhandler);
44 modify_main_caps(UNSET, g_data->tty);
45 update_data(g_data);
46 print_args(g_data);
47 update_cursor(g_data, 1);
48 }
49 else if (sig == SIGINT)
50 {
51 enable_cap("te");
52 modify_main_caps(SET, g_data->tty);
53 exit(EXIT_FAILURE);
54 }
55 }
CTRL + Z 导致终端设备驱动程序将SIGTSTP
发送到前台进程组.至少在bash
和zsh
中,命令替换$(<command>)
中的命令在子shell中执行,但是它们没有得到自己的进程组(它们在同一进程中运行)组作为父外壳本身).这意味着 CTRL + Z 完全不会影响它们-按下它并没有任何反应,就像按下 CTRL + Z 在shell提示符下什么也不做:在两种情况下,都没有要挂起的前台进程组!
CTRL+Z causes the terminal device driver to send a SIGTSTP
to all processes in the foreground process group. In bash
and zsh
, at least, commands in a command substitution $(<command>)
are executed in a subshell, but they don't get their own process group (they run in the same process group as the parent shell itself). That means that CTRL+Z should not affect them at all - press it and nothing happens, just like pressing CTRL+Z in a shell prompt doesn't do anything: in both cases, there is no foreground process group to suspend!