You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS系统中dhcpd服务停止方法及service dhcpd stop执行原理

What happens when you run service dhcpd stop on CentOS?

Great question! The service command is just a wrapper script that delegates the actual work to the system's service management tools. Let's break down exactly what happens when you run service dhcpd stop, depending on your CentOS version:

For CentOS 6 and older (SysVinit system)

On these systems, service dhcpd stop directly calls the init script located at /etc/init.d/dhcpd, specifically executing its stop function. Here's what that function does step-by-step:

  • Locate the PID file: First, it checks for the dhcpd process ID (PID) stored in /var/run/dhcpd.pid (the exact path might vary slightly by config, but this is the default). If the file doesn't exist, it will usually output a message saying the service isn't running.
  • Send a graceful stop signal: It reads the PID from the file and sends a SIGTERM signal (via kill <PID>). This tells the dhcpd process to wrap up any ongoing tasks (like finishing lease updates) before shutting down cleanly.
  • Force termination if needed: If the process doesn't exit after a short wait (usually a few seconds), the script will escalate to sending a SIGKILL signal (kill -9 <PID>) to force the process to stop immediately.
  • Clean up: Finally, it removes the PID file to avoid confusion during future service starts, and outputs a confirmation message that the service has been stopped.

For CentOS 7 and newer (SystemD system)

Even though service dhcpd stop still works for backward compatibility, it's actually a wrapper for systemctl stop dhcpd.service. Here's what SystemD does:

  • Check service status: SystemD first verifies if the dhcpd service is active.
  • Trigger the stop unit: It uses the service's systemd unit file (usually /usr/lib/systemd/system/dhcpd.service) to initiate the stop process. This unit file defines how the service should be stopped, typically sending a SIGTERM first.
  • Wait and force if necessary: Like the SysVinit script, SystemD will wait for a configurable timeout period. If the process doesn't exit in time, it sends SIGKILL to terminate it.
  • Update service state: It marks the service as stopped in the systemd manager and updates the status output for tools like systemctl status dhcpd.

If you want to see exactly what the init script does on older systems, you can open it directly with a text editor:

cat /etc/init.d/dhcpd

Look for the stop() function inside—it will have all the logic we walked through above.

内容的提问来源于stack exchange,提问作者YH Wang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:33:01