{"record":{"id":"02341b223f15939c","repo":"fluent/fluentd","slug":"pid-pid-is-running","errorCode":null,"errorMessage":"pid(#{pid}) is running","messagePattern":"pid\\(#(.+?)\\) is running","errorType":"exception","errorClass":"Fluent::ConfigError","httpStatus":null,"severity":"error","filePath":"lib/fluent/daemonizer.rb","lineNumber":68,"sourceCode":"      pid\n    end\n\n    def check_pidfile(pid_path)\n      if File.exist?(pid_path)\n        if !File.readable?(pid_path) || !File.writable?(pid_path)\n          raise Fluent::ConfigError, \"Cannot access pid file: #{pid_path}\"\n        end\n\n        pid =\n          begin\n            Integer(File.read(pid_path), 10)\n          rescue TypeError, ArgumentError\n            return # ignore\n          end\n\n        begin\n          Process.kill(0, pid)\n          raise Fluent::ConfigError, \"pid(#{pid}) is running\"\n        rescue Errno::EPERM\n          raise Fluent::ConfigError, \"pid(#{pid}) is running\"\n        rescue Errno::ESRCH\n        end\n      else\n        unless File.writable?(File.dirname(pid_path))\n          raise Fluent::ConfigError, \"Cannot access directory for pid file: #{File.dirname(pid_path)}\"\n        end\n      end\n    end\n\n    def install_at_exit_handlers(pidfile)\n      at_exit do\n        if File.exist?(pidfile)\n          File.delete(pidfile)\n        end\n      end\n    end","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/daemonizer.rb#L50-L86","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Stop the running instance first: kill $(cat /path/to/fluentd.pid), wait for exit, then start","Verify what the pid is before killing: ps -p $(cat /path/to/fluentd.pid) to avoid killing a reused pid","If the pid belongs to an unrelated process (pid reuse), remove the stale pidfile and start","Use distinct pidfile paths per fluentd instance and let one supervisor own start/stop"],"exampleFix":"# before\n$ fluentd --daemon /var/run/fluentd.pid ...   # error: pid(1234) is running\n\n# after\n$ ps -p $(cat /var/run/fluentd.pid)   # confirm it is the old fluentd\n$ kill $(cat /var/run/fluentd.pid) && sleep 2\n$ fluentd --daemon /var/run/fluentd.pid ...","handlingStrategy":"validation","validationCode":"pid = File.read(path).to_i\nbegin\n  Process.kill(0, pid)\n  abort \"fluentd already running as pid #{pid}\"\nrescue Errno::ESRCH\n  File.delete(path) # stale\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use one supervisor (systemd) to serialize start/stop and wait for exit before restart","Give each fluentd instance its own pidfile path","Always run ps -p $(cat pidfile) before acting on a recorded pid (pid reuse)"],"tags":["fluentd","daemon","pidfile","process-management"],"backgroundTag":"process-already-running","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}