One of the server that I am working with has some infinitely running PHP process. Due to incorrect way of cron setup by the development team, it has caused the process hanging and not ended properly. According to them, these processes can be killed if still hang after 12 hours.
Any process which run in server will have start time (STIME). You can check this by using ps command. In this case, following result will appear:
If you see the STIME value mostly has started long time ago but it is still inside the process list. To kill all the older process which more that 24 hours, I use following command:
Explanation:
Using ps command, we grep anything related to “php” and “sync2server” which is the specific process that we want to kill. The 4th argument is checking whether column no 9 (STIME) column has value which NOT in “number:number” format. Process which starts for more than 24 hours, STIME value will contains word for example “Jun23″ or “2010″. The 5th argument is actually print the value of column no 2 which is the PID to be killed.
Using ps command, we grep anything related to “php” and “sync2server” which is the specific process that we want to kill. The 4th argument is checking whether column no 9 (STIME) column has value which NOT in “number:number” format. Process which starts for more than 24 hours, STIME value will contains word for example “Jun23″ or “2010″. The 5th argument is actually print the value of column no 2 which is the PID to be killed.
To kill process which less than 24 hours, you can use following script:
Above scripts will try to find any PHP process which executed more than 12 hours and will kill it one by one. You can get the script to run as cron twice per day so it will automate your administration job.
Lets share if you have better idea. Cheers!
댓글 없음:
댓글 쓰기