I am having an issue in a PHP application, where some processes seem to run for days - still trying to work out how/why but, whilst this happens, the resources on the server get zapped and loads goes way up. I then manually go in and kill the processes and everything is fine until it happens again
Therefore, as a stop gap, I want to run a cron to kill all php processes older than say 1 hour
When I get a list of processes it shows me below (I have removed all the ones which are not relevant)
2049 7204994 php-fpm: master process (/etc/php-fpm.conf) 42146 42087 php-fpm: pool www -DFOREGROUND 47118 49511 php-fpm: pool www 47119 49511 php-fpm: pool www 47162 47222 php-fpm: pool www -- uid 0 -- gid 0 -- logger=files 47280 39490 php-fpm: pool www 51993 12066 php-fpm: pool www 51994 12066 php-fpm: pool www 53634 8575 php-fpm: pool www 53749 2590 php-fpm: pool www 53775 766 php-fpm: pool www 53780 447 php-fpm: pool www 53781 358 php-fpm: pool www 53784 111 php-fpm: pool www 53797 26 php-fpm: pool www 53799 0 ps -eo pid,etimes,cmd I want to be able to kill any process older than 3600 seconds BUT not including the master process or those with additional arguments
If I try
ps -eo pid,etimes,cmd | awk '$2 > 3600 && $3 == "php-fpm: pool www"' then nothing is returned at all.
If I try
ps -eo pid,etimes,cmd | awk -v pat="php-fpm" '$2 > 3600 && $3 ~ pat' this returns me all of the above which I do not want as I do not want to kill the master process but if I try
ps -eo pid,etimes,cmd | awk -v pat="php-fpm: pool" '$2 > 3600 && $3 ~ pat' OR
ps -eo pid,etimes,cmd | awk -v pat="pool" '$2 > 3600 && $3 ~ pat' then I get nothing returned at all
How can I get this to return only those where the pattern contains exactly "php-fpm: pool www" and nothing else?