Fixing “cron: can’t lock /var/run/crond.pid” Error on Debian: PID Conflict Resolution


1 views

When you encounter the error cron: can't lock /var/run/crond.pid, otherpid may be 3759, it indicates a process ID (PID) file conflict. The cron daemon uses this file to ensure only one instance runs at a time. Here's what's happening under the hood:

# Typical cron daemon startup sequence
/usr/sbin/cron -f -P
# Creates /var/run/crond.pid with its process ID

Try these troubleshooting steps in order:

# 1. Check if cron is actually running
ps aux | grep cron

# 2. Verify the PID file contents
cat /var/run/crond.pid

# 3. Force remove the stale PID file (if safe)
sudo rm -f /var/run/crond.pid

# 4. Restart the cron service properly
sudo systemctl restart cron

If rebooting didn't resolve the issue (as in your case), the problem might be:

  • A hung cron process that survived reboot (check dmesg)
  • Filesystem corruption preventing PID file cleanup
  • Custom cron configuration interfering

For persistent cases, try these diagnostic commands:

# Check for file locks
sudo lsof /var/run/crond.pid

# Verify inode information
ls -li /var/run/crond.pid

# Check system logs
journalctl -u cron --no-pager -n 50

To avoid this issue:

  1. Always stop cron properly: sudo systemctl stop cron
  2. Consider adding a cron service unit override:
# /etc/systemd/system/cron.service.d/override.conf
[Service]
ExecStartPre=/bin/rm -f /var/run/crond.pid

When you encounter the error message cron: can't lock /var/run/crond.pid, otherpid may be 3759: Resource temporarily unavailable, it typically indicates that the cron daemon is either already running or left a stale PID file behind. This commonly happens after improper service termination or manual intervention with cron configurations.

First, verify if there are any existing cron processes:

ps aux | grep cron
# Or more specifically:
pgrep cron

If you see multiple cron processes or the PID mentioned in your error (3759 in this case), you'll need to terminate them:

sudo kill -9 3759
# Or to kill all cron processes:
sudo pkill cron

The next step is to remove the lock file that's causing the issue:

sudo rm /var/run/crond.pid
# On some systems it might be:
sudo rm /var/run/cron.pid

After cleaning up, restart the cron service:

sudo systemctl restart cron
# For older systems:
sudo service cron restart

Check if cron is running properly:

systemctl status cron
# Or:
service cron status

You should see active (running) status without any errors.

To avoid this issue in the future:

  • Always use proper service commands (systemctl/service) to manage cron
  • Avoid manually killing cron processes unless absolutely necessary
  • When modifying cron configurations, use crontab -e rather than direct file edits

If the problem persists, check system logs for more details:

sudo tail -n 50 /var/log/syslog | grep cron
journalctl -u cron --no-pager -n 50

You might also want to verify file permissions:

ls -la /var/run/cron*
stat /var/run/crond.pid

Correct permissions should be:

-rw-r--r-- 1 root root