Kill child process when the parent exits
Posted
by
kolypto
on Server Fault
See other posts from Server Fault
or by kolypto
Published on 2014-05-28T18:54:56Z
Indexed on
2014/05/28
21:33 UTC
Read the original article
Hit count: 185
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.
© Server Fault or respective owner