Ankur Agarwal
Ankur Agarwal

Reputation: 24748

SIGTERM not reported as 143 during trap

#!/bin/sh

echo "Running $(basename $0) $*"

function on_err {
echo $?
echo "error happened"

}


trap "on_err" 2 15
while true
do
:
done

$ kill -15 pid

gives

0
error happened

I was hoping to see

143
error happened

Upvotes: 1

Views: 169

Answers (1)

ntshetty
ntshetty

Reputation: 1305

Do something in while loop instead spinning infinite.

while true
do
 sleep 1
done

use kill -15 -PID instead kill -15 PID

Output:

Running test.sh 
0
Terminated: 15
143

Upvotes: 1

Related Questions