fluent/fluentd · error · Fluent::ConfigError

pid(#{pid}) is running

Error message

pid(#{pid}) is running

What it means

During daemon startup, check_pidfile reads the numeric pid from the pidfile and probes it with Process.kill(0, pid): signal 0 does nothing but succeeds only if the process exists and is signalable. A success means a live process owns that pid — almost always a previous fluentd still running — and fluentd refuses to start a second daemon. This is the intentional duplicate-daemon guard; note pid reuse can point it at an unrelated process.

Source

Thrown at lib/fluent/daemonizer.rb:68

      pid
    end

    def check_pidfile(pid_path)
      if File.exist?(pid_path)
        if !File.readable?(pid_path) || !File.writable?(pid_path)
          raise Fluent::ConfigError, "Cannot access pid file: #{pid_path}"
        end

        pid =
          begin
            Integer(File.read(pid_path), 10)
          rescue TypeError, ArgumentError
            return # ignore
          end

        begin
          Process.kill(0, pid)
          raise Fluent::ConfigError, "pid(#{pid}) is running"
        rescue Errno::EPERM
          raise Fluent::ConfigError, "pid(#{pid}) is running"
        rescue Errno::ESRCH
        end
      else
        unless File.writable?(File.dirname(pid_path))
          raise Fluent::ConfigError, "Cannot access directory for pid file: #{File.dirname(pid_path)}"
        end
      end
    end

    def install_at_exit_handlers(pidfile)
      at_exit do
        if File.exist?(pidfile)
          File.delete(pidfile)
        end
      end
    end

View on GitHub (pinned to dd45c6e18d)

Solutions

  1. Stop the running instance first: kill $(cat /path/to/fluentd.pid), wait for exit, then start
  2. Verify what the pid is before killing: ps -p $(cat /path/to/fluentd.pid) to avoid killing a reused pid
  3. If the pid belongs to an unrelated process (pid reuse), remove the stale pidfile and start
  4. Use distinct pidfile paths per fluentd instance and let one supervisor own start/stop

Example fix

# before
$ fluentd --daemon /var/run/fluentd.pid ...   # error: pid(1234) is running

# after
$ ps -p $(cat /var/run/fluentd.pid)   # confirm it is the old fluentd
$ kill $(cat /var/run/fluentd.pid) && sleep 2
$ fluentd --daemon /var/run/fluentd.pid ...
Defensive patterns

Strategy: validation

Validate before calling

pid = File.read(path).to_i
begin
  Process.kill(0, pid)
  abort "fluentd already running as pid #{pid}"
rescue Errno::ESRCH
  File.delete(path) # stale
end

Prevention

When it happens

Trigger: Running a second 'fluentd --daemon PIDFILE' while the first daemon is still alive; a restart script that does not wait for the old process to exit; an unclean shutdown long ago with the pid since reassigned to another process.

Common situations: Rolling restart scripts racing the old process shutdown; supervisor/systemd plus a manual daemon double-start; stale pidfile whose pid was reused by the OS.

Related errors


AI-assisted analysis of fluent/fluentd@dd45c6e18d (2026-08-21). Data as JSON: /api/errors/02341b223f15939c. Report an issue: GitHub.