Search code examples
shellcygwinbackground-process

Background process called from script, dies after it ends


Something weird is happening on Cygwin. I run a script that put some processes into background. However as soon as the script ends, they all die.

Simple example, take this script:

tail -f logfile.log &

I can see that the tail works (it prints the last X lines) but the process is not in the background anymore as soon as the script ends.

On Linux it behave differently, any idea why ?


Solution

  • I would try nohup *cmd* & on linux. But you will need to account for the file descriptors that get passed to the child. So nohup *cmd* </dev/null >/dev/null 2>&1 & but where will the tail -f output go? Does the window close when you exit the shell? Then you can't exit the shell if you want to see the output.