# File lib/scout/command.rb, line 178
    def create_pid_file_or_exit
      pid_file = File.join(config_dir, "scout_client_pid.txt")
      begin
        File.open(pid_file, File::CREAT|File::EXCL|File::WRONLY) do |pid|
          pid.puts $$
        end
        at_exit do
          begin
            File.unlink(pid_file)
          rescue
            log.error "Unable to unlink pid file:  #{$!.message}" if log
          end
        end
      rescue
        pid     = File.read(pid_file).strip.to_i rescue "unknown"
        running = true
        begin
          Process.kill(0, pid)
        rescue Errno::ESRCH
          running = false
        rescue
          # do nothing, we didn't have permission to check the running process
        end
        if running
          log.warn "Process #{pid} was already running" if log
          exit
        else
          log.info "Stale PID file found.  Clearing it and reloading..." if log
          File.unlink(pid_file) rescue nil
          retry
        end
      end
      
      self
    end