How to terminate a process(httpd) when its PID keeps on changing in CENTOS 7

17,518

Solution 1

You have to understand that when you grep httpd you'll not just get back any apache processes but the grep process as well. You're seeing your own command reflected back at you.

# ps ax | grep httpd
1818 ? Ss 0:53 /usr/sbin/httpd
38729 ? S 4:38 /usr/sbin/httpd
38730 ? S 4:49 /usr/sbin/httpd
54915 pts/0 S+ 0:00 grep httpd

Solution 2

Try:

find / -name "httpd.pid"
Then delete the pid file, if it exists.

Also, just in case:

systemctl stop httpd
systemctl disable httpd

Machavity is right too, whenever you grep from the output of ps you're going to see your grep command too. It's something you'll get used to.

Share:
17,518

Related videos on Youtube

Anup Sharma
Author by

Anup Sharma

Updated on September 18, 2022

Comments

  • Anup Sharma
    Anup Sharma over 1 year

    When I tried to restart my httpd service using systemctl restart httpd

    Checking the status, I found that process is dead and another process is running. so I removed it using yum erase httpd

    As a precaution, I checked if the process is still running using ps aux | grep httpd# and found it was but this time the PID was different. and after subsequent queries, the PID kept on changing. If I try to kill using any PID, it would say NO Such Process

    Check the screenshot:

    enter image description here

    Hence the question. How do I stop this process so that I can install the service from scratch and configure it?

    • Andrés Sánchez García
      Andrés Sánchez García almost 9 years
      This PID isn't http process. This PID is grep proccess. Try "systemctl status httpd" for check httpd status. But if you erase httpd package, you haven't any process of httpd
    • Anup Sharma
      Anup Sharma almost 9 years
      Exactly my question. When i have already erased the httpd package, how am I getting httpd (pid 22595) already running .
    • faker
      faker almost 9 years
      You also grep for httpd# including the #. Remove the # to actually properly match for httpd.
  • Anup Sharma
    Anup Sharma almost 9 years
    Unserstood. But still if I try systemctl status httpd , I get the same error as httpd (pid 22595) already running and Failed to start The Apache HTTP Server.
  • Machavity
    Machavity almost 9 years
    Try this instead service httpd status
  • Anup Sharma
    Anup Sharma almost 9 years
    Same Error. Also when I try to kill 22595, it says NO such process
  • Machavity
    Machavity almost 9 years
    My best guess then is that the httpd.pid file still exists and the system is returning that. Since your grep is empty you might want to make sure that file was deleted
  • Machavity
    Machavity almost 9 years
    Mine lives at /var/run/httpd/httpd.pid
  • Anup Sharma
    Anup Sharma almost 9 years
    Hmmm, no such folder as httpd in run. So could it be any other error?
  • Machavity
    Machavity almost 9 years
    Beyond rebooting I don't have any other suggestions
  • Anup Sharma
    Anup Sharma almost 9 years
    Tried that but didn't work. @Machavity 's suggestion of restart worked.