2

How can I execute some command after the named pipe has been readout in other end. I was trying to use trap. But nothing happens. My script is something like below.

#!/bin/sh

cleanup()
{
  echo "Caught Signal ... cleaning up the background process."
}

trap cleanup PIPE

if [ ! -p "/tmp/mysqld.init" ]; then
    mkfifo /tmp/mysqld.init
fi

echo  "CREATE DATABASE IF NOT EXISTS test;" > /tmp/mysqld.init &

exec mysqld --init-file="/tmp/mysqld.init"

Note: This is my docker image's entrypoint script and exec is necessary in my case.

  • If the exec is successful, the shell will no longer exist, so there's no way for the shell to write to a closed pipe and no way the trap body would run. What do you want to do after the pipe has been read? – Mark Plotnick Jan 20 at 15:56
  • I am not sure what do you mean by shell will no longer exist. But in my case as I am creating a docker image mysqld runs as pid 1 for ever. I just want to close the child/background process after the pipe has been read. – SkyRar Jan 20 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.