           console.log "couldn't delete previous process tree at #{previouschildProcessesContainerDir}"
         #else
         #  console.log "previous process tree is deleted."
+        
   fork: (options,callback) ->
     options.fork = yes
     @run options,callback, (cb) =>

          workerExchange.publish "input.worker", {worker: @workerProcess[name].worker},
            appId: "#{@workerProcess[name].worker.uuid}"

    ################################
    ### HANDLE SIGNALS and KILLS ###
    ################################

    # When doing ctrl+c, let kontrold now we are dead
    process.on 'SIGINT', =>
      @workerProcess[name].worker.status = 5
      @workerProcess[name].fetchWorkerExchange (workerExchange) =>
        @workerProcess[name].worker.message.command = "ack"
        workerExchange.publish "input.worker", {worker: @workerProcess[name].worker},
          appId: "#{@workerProcess[name].worker.uuid}"
        process.exit(0)

    # When sending SIGTERM (aka kill -15, killall, ...), let kontrold know we are death
    process.on 'SIGTERM', =>
      console.log "going down"
      @workerProcess[name].worker.status = 5
      @workerProcess[name].fetchWorkerExchange (workerExchange) =>
        @workerProcess[name].worker.message.command = "ack"
        workerExchange.publish "input.worker", {worker: @workerProcess[name].worker},
          appId: "#{@workerProcess[name].worker.uuid}"
        process.exit(0)

  populateChildObject: (options, @child) ->
    {name,onMessage,modulePath,args,restart,restartTimeout,cmd,log,onExit,stdout,stderr,verbose,die} = options
    onExit ?= ->

catch e
  # do nothing, probably dir is already there.

################################
### HANDLE SIGNALS and KILLS ###
################################

# when doing ctrl+c 
process.on 'SIGINT', =>
  console.log "\nkilled via ctrl+c. this should not happen"
  process.exit(0)

# guaranteed death.
process.on 'SIGTERM', =>
  console.log "going down"
  process.exit(0)

class Processes extends EventEmitter
  constructor:(options={})->
    {main}         = options
    @list          = {}
    @child         = null
    @workerProcess = {}
    @childProcessesContainerDir = __dirname+"/.tmp"
    if main
