Fork current process into the background

From Urandom
Jump to navigation Jump to search

So i wanted to create a simple script that had to go into the background, but I did not want to call

nohup command & 

Instead I wanted to let the program do that itself. I found that if we are dealing with simple scripts then this is a quick and dirty way to achieve this. Should work well with any distro.

if [ "$1" != "nohupme" ] #just to fork it to background
nohup $0 nohupme 2>&1 > $0.log &

else #actual program

  echo "Program goes here"