Fork current process into the background

From Urandom
Revision as of 05:09, 10 May 2013 by Martivo (talk | contribs) (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…")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, 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.

#!/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