Why is `timeout 2 timeout 1 bash` stuck

I am learning a command timeoutin a Linux shell.

When I try timeout 1 bash, bash will start and be killed in 1 second.

When I try timeout 2 timeout 1 yes, the program yeswill run for 1 second and the second one will be killed timeout.

But when I try timeout 2 timeout 1 bash, it gets stuck. The bash shell is not displayed, and it continues to work, even if I press Ctrl + C.

I know that you should not write two timeoutin one team.

I just wonder why this will happen.

+4
source share
1 answer

Here is another example of the same behavior:

strace timeout 1 bash strace, bash .

bash , .

--- SIGTTIN {si_signo = SIGTTIN, si_code = SI_USER, si_pid = 7162, si_uid = 1000} --- rt_sigaction (SIGTTIN, {sa_handler = SIG_IGN, sa_mask = [], sa_flags = SA_RESTORER, sa_restorer = 0x7f097723a7e0}, {sa_handler = SIG_DFL, sa_mask = [], sa_flags = SA_RESTORER, sa_restorer = 0x7f097723a7e0}, 8) = 0 ioctl (255, TIOCGPGRP, [6412])
= 0 rt_sigaction (SIGTTIN, {sa_handler = SIG_DFL, sa_mask = [], sa_flags = SA_RESTORER, sa_restorer = 0x7f097723a7e0}, {sa_handler = SIG_IGN, sa_mask = [], sa_flags = SA_RESTORER, sa_restorer = 0x7f097723a7e0}, 8) = 0 kill (0, SIGTTIN) = 0

, http://www.gnu.org/software/libc/manual/html_node/Job-Control-Signals.html

: int SIGTTIN

. - , SIGTTIN. - . , , . .

timeout 2 timeout --foreground 1 bash , - tty, .

   --foreground

          when not running timeout directly from a shell prompt,

          allow COMMAND to read from the TTY and get TTY signals; in this mode, children of COMMAND will not be timed out

-, , , , --foreground:

timeout 3 timeout --foreground 2 timeout --foreground 1 bash

SIGNALS man bash , bash .

+1

Source: https://habr.com/ru/post/1663199/


All Articles