Results 1 to 6 of 6
Hi,
My server pretty often becomes full up php processes running which are not needed.
Is there a way to search for and kill any php process that is more ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-15-2010 #1
kill process more than 3 hours old from shell command
Hi,
My server pretty often becomes full up php processes running which are not needed.
Is there a way to search for and kill any php process that is more than 3 hours old?
as I understand it, i need to use ps piped with awk. awk at the moment seems very complicated to me, do not how to start tackling it.
- 11-15-2010 #2
In theory this can be done, but it is a bad solution.
If a php process (what kind? cron, application, mod_php?) is not needed anymore,
it should exit by itself.
Or the other way around: How can you be sure, that all processing has been done after 3h?
imho, for mod_php and php cronjobs: write an error ticket to the devs and let them figure out proper exit conditions.
If it is intended, that one process runs long, then at least the forks or threads should exit.You must always face the curtain with a bow.
- 11-15-2010 #3
The php processes are to do with voice calls that are being handled by server.
Sometimes the call terminates but the php script continues to run. Even if the call is really active, i do not want any calls to last more than 3 hours.
- 11-16-2010 #4Just Joined!
- Join Date
- Mar 2010
- Location
- Grand Rapids, MI
- Posts
- 15
As Irithori stated. killing these processes is a hack. The best solution is to fix the scripts to timeout properly. If that's not possible, you can write a wrapper script to manage the timeout.
Unfortunately, I have a similar case where I need to reap processes due to a customers buggy ssh client. Here's an quick cmd line to list / grep / kill all sshd processes containing the string X in the ps output:
ps -C sshd --format pid,start_time,start,cmd --no-headers | grep X | awk '{print $1}' | xargs -i kill -15 {}
The awk section only grabs and prints column 1, which is the pid. So if you want to grab php process that started between 02:00:00 and 03:00:00, you could use:
ps -C php --format pid,start_time,start,cmd --no-headers | grep 02:..:.. | awk '{print $1}' | xargs -i kill -15 {}
To limit based on time is a bit more difficult to automate, as you'll need something to determine which times occur over 3 hours ago, and I don't know of any simple command line programs which do this.
Good luck.
- 11-16-2010 #5Just Joined!
- Join Date
- Dec 2006
- Posts
- 6
- 11-16-2010 #6
Ramesh, the script name varies. But the general format is like this
All these processes start with /usr/bin/php -q.Code:root 16001 0.0 0.1 157448 6700 ? S Nov15 0:00 /usr/bin/php -q /home/voice/ivr/dial_through/ldial_through.php ddi=12345678912 type =ivr name= ccode=code_name acode=mob root 16002 0.0 0.1 157448 6696 ? S 07:07 0:00 /usr/bin/php -q /home/voice/ivr/play_audio.php ddi=98765432178 type =ivr name= ccode=code_name acode=mob


Reply With Quote

