Home Why is parent bash waiting for child bash to die to execute trap
Reply: 0

Why is parent bash waiting for child bash to die to execute trap

user1646
1#
user1646 Published in April 24, 2018, 6:43 am

This question already has an answer here:

  • Interrupt sleep in bash with a signal trap 3 answers
  • Catch signal in bash but don't finish currently running command 1 answer

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

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.320523 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO