Difference between revisions of "Fork current process into the background"

From Urandom
Jump to: navigation, search
(Created page with "So i wanted to create a simple script that had to go into the background, but I did not want to call <pre> nohup command & </pre> Instead I wanted to let the program do that it…")
 
(No difference)

Latest revision as of 05:09, 10 May 2013

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.

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

else #actual program

  echo "Program goes here"

fi