Answer the question
In order to leave comments, you need to log in
Bash, trap signal?
There is a simple script
#!/bin/bash
trap 'echo Catched' TERM
echo $$
#cat /dev/zero |
while true ; do
sleep 1
done
kill -TERM [PID]
cat /dev/zero |
#!/bin/bash
trap 'echo Catched' TERM
echo $$
cat /dev/zero |
while true ; do
sleep 1
done &
while : ; do
wait $!
done
Answer the question
In order to leave comments, you need to log in
bash man:
If bash is waiting for a command to complete and receives a signal for which a trap has been set, the trap will not be executed until the command completes. When bash is waiting for an asynchronous command via the wait builtin, the reception of a signal for which a trap has been set will cause the wait builtin to return immediately with an exit status greater than 128, immediately after which the trap is executed.
Have you tried another command that does not hang pending like
cat /dev/zero |
?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question