Kill child process when the parent exits
- by kolypto
I'm preparing a script for Docker, which allows only one top-level process, which should receive the signals so we can stop it.
Therefore, I'm having a script like this: one application writes to syslog (bash script in this sample), and the other one just prints it.
#! /usr/bin/env bash
set -eu
tail -f /var/log/syslog &
exec bash -c 'while true ; do logger aaaaaaaaaaaaaaaaaaa ; sleep 1 ; done'
Almost solved: when the top-level process bash gets SIGTERM -- it exists, but tail -f continues to run.
How do I instruct tail -f to exit when the parent process exits? E.g. it should also get the signal.
Note: Can't use bash traps since exec on the last line replaces the process completely.