我有一个类似脚本的文本菜单,用于一些小的操作。 在其中有一个读取命令。 例如
read response
现在说脚本是否已运行,它将等待用户输入。我让它保持空闲状态,等待TMOUT启动。我只是想捕获此信号并退出。
所以我只是尝试:
trap 'exit' ALRM
read response
但是它不起作用,脚本本身只是一种循环(例如,再次刷新此菜单)
当TMOUT出现时,我试图对此进程进行跟踪,并且确实看到了SIGARLM,它在select子系统调用之后启动,但是脚本由于某种原因而忽略了它? 唯一起作用的是,如果我执行“ trap exit ERR”而不是“ trap exit ALRM”
有什么建议吗?
跟踪:
06:49:22 select(1, [0], NULL, NULL, NULL) = ? ERESTARTNOHAND (To be
restarted if no handler)
06:49:32 --- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
06:49:32 alarm(0) = 0
06:49:32 rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
06:49:32 ioctl(0, SNDCTL_TMR_START or TCSETS, {B38400 opost isig icanon echo
...}) = 0
06:49:32 ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
06:49:32 write(1, "\n###############################"..., 327) = 327
06:49:32 write(1, "Your choice: ", 13) = 13
06:49:32 rt_sigaction(SIGALRM, {0x453d70, [], SA_RESTORER|SA_INTERRUPT,
0x7f407e998250}, {0x453d70, [], SA_RESTORER|SA_INTERRUPT, 0x7f407e998250},
8) = 0
06:49:32 setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={20, 0}},
{it_interval={0, 0}, it_value={0, 0}}) = 0
06:49:32 rt_sigaction(SIGWINCH, {0x41a760, [], SA_RESTORER|SA_INTERRUPT,
0x7f407e998250}, {0x41a760, [], SA_RESTORER|SA_INTERRUPT, 0x7f407e998250},
8) = 0
06:49:32 ioctl(2, TIOCGWINSZ, {ws_row=59, ws_col=211, ws_xpixel=0,
ws_ypixel=0}) = 0
06:49:32 rt_sigprocmask(SIG_UNBLOCK, [WINCH], NULL, 8) = 0
06:49:32 ioctl(2, TCGETS, {B38400 opost isig icanon echo ...}) = 0
06:49:32 ioctl(2, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost -isig -icanon -
echo ...}) = 0
06:49:32 select(1, [0], NULL, NULL, NULL) = ? ERESTARTNOHAND (To be
restarted if no handler)
06:49:52 --- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
06:49:52 alarm(0) = 0
06:49:52 rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
06:49:52 ioctl(0, SNDCTL_TMR_START or TCSETS, {B38400 opost isig icanon echo
...}) = 0
06:49:52 ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
06:49:52 write(1, "\n###############################"..., 327) = 327
06:49:52 write(1, "Your choice: ", 13) = 13
06:49:52 rt_sigaction(SIGALRM, {0x453d70, [], SA_RESTORER|SA_INTERRUPT,
0x7f407e998250}, {0x453d70, [], SA_RESTORER|SA_INTERRUPT, 0x7f407e998250},
8) = 0
06:49:52 setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={20, 0}},
{it_interval={0, 0}, it_value={0, 0}}) = 0
06:49:52 rt_sigaction(SIGWINCH, {0x41a760, [], SA_RESTORER|SA_INTERRUPT,
0x7f407e998250}, {0x41a760, [], SA_RESTORER|SA_INTERRUPT, 0x7f407e998250},
8) = 0
06:49:52 ioctl(2, TIOCGWINSZ, {ws_row=59, ws_col=211, ws_xpixel=0,
ws_ypixel=0}) = 0
06:49:52 rt_sigprocmask(SIG_UNBLOCK, [WINCH], NULL, 8) = 0
06:49:52 ioctl(2, TCGETS, {B38400 opost isig icanon echo ...}) = 0
06:49:52 ioctl(2, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost -isig -icanon -
echo ...}) = 0
06:49:52 select(1, [0], NULL, NULL, NULL^Cstrace: Process 26653 detached