bash - Why does my trap does not work? -
i have written below script:
#!/bin/bash sleep 15 function_signalr() { date date | awk '{printf "%-15s\n", $2}' } trap "function_signalr" 10 when start process "process &" runs, pid given. kill -10 pid, trap not work. process killed, trap did not sprung. no date message given. grateful advice.
your trap doesn't work because shell doesn't know yet.
you need define trap function, set trap , write code.
#!/bin/bash function_signalr() { date date | awk '{printf "%-15s\n", $2}' } trap "function_signalr" 10 # code follows sleep 15 moreover note sleep blocking implies if kill -10 pid trap wouldn't execute until sleep done.
Comments
Post a Comment