Let's say I have a shell and another external shell. On the first shell I run bash: This is the parent bash. In the parent bash I set a trap with trap exit INT for example. Then I run bash again inside this parent bash, so I get a child bash where I do whatever. Then from the external shell, if I try to kill the parent bash's PID with -INT flag it does not do anything. Once I exit the child bash then it returns to the parent bash and executes the trap and kills the parent bash right away.
My main question is How can I force a trap to be executed right away, even if the corresponding bash has some subshells open? How can I work around it? I don't want brutal execution like -9 since I still want my bash's trap to do specific clean up work.
INT doesnt seem to matter. Example: In one shell run:
bash
ps
trap "echo HELLO" TERM
bash
In the other shell write:
kill -TERM (pid that you read in ps)
it won't do anything until you actually exit the child bash