python - What does this daemonize method do? -


i looking around on github, when stumbled across method called daemonize() in reverse shell example. source

what don't quite understand in context, wouldn't running code command line such: python example.py & not achieve same thing?

deamonize method source:

def daemonize():     pid = os.fork()     if pid > 0:         sys.exit(0)   # exit first parent     pid = os.fork()     if pid > 0:         sys.exit(0)   # exit second parent 

a background process - running python2.7 <file>.py & signal - not same thing true daemon process.

a true daemon process:

  • runs in background. happens if use &, , similarity ends.
  • is not in same process group terminal. when terminal closes, daemon not die either. not happen & - process remains same, moved background.
  • properly closes inherited file descriptors (including input, output, etc.) nothing ties parent. again, not happen & - still write terminal.
  • should ideally killed sigkill, not sighup. running & allows process killed sighup.

all of this, however, pedantry. few tasks require go extreme these properties require - background task spawned in new terminal using screen can same job, though less efficiently, , may call daemon in long-running background task. real difference between that , true daemon latter tries avoid avenues of potential death.

the code saw forks current process. essentially, clones current process, kills parent , 'acts in background' being separate process not block current execution - bit of ugly hack, if ask me, works.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -