3

I have the following bash script:

#!/bin/bash
set -m
(
    (bin/pnvd &> /dev/null; kill 0) &
    sleep 2
    perl integration-test/fuzz-test.pl || kill 0
    kill %1
)

The first three commands in the subshell succeed and return exit status 0. bin/pnvd never exits until it is killed externally.

However after executing the forth command in the subshell, the script exits with this output:

tools/integration-test: line 8:  4712 Terminated              ( ( bin/pnvd &> /dev/null; kill 0 ) & sleep 2; perl integration-test/fuzz-test.pl || kill 0; kill %1 )

and status code 143.

It looks as if kill %1 kills the whole process group, not just the first job, however if I remove set -m then it exits with status 0.

I am not so much interested in how to fix this but more in: why does the subshell exit with status 143 when it kills the first job?

1

1 Answer 1

2

Quote from https://stackoverflow.com/a/7294947/402322

Also, if the program dies because of a signal, bash lets you know by encoding the exit status as:

128 + signal-number

Hence SIGHUP yields 129, SIGILL yields 132, SIGTERM yields 143, etc.

The above means, that your process has got SIGTERM.

You have three kills in your code. If you can exclude kill %1 one of the other two kill 0 sends the TERM signal.

2

You must log in to answer this question.