I have a bunch of processes owned by apache that are running for days because they are stuck.
apache 11173 0.1 0.0 228248 27744 ? Ss Sep27 3:58 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 12609 0.1 0.0 228244 27744 ? Ss Sep18 19:30 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 14646 0.1 0.0 228244 27744 ? Ss Sep17 21:30 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 15900 0.1 0.0 228244 27744 ? Ss Sep20 15:46 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 16169 0.1 0.0 228248 27752 ? Ss Sep22 12:16 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 16887 0.1 0.0 228244 27748 ? Ss Sep21 14:04 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 16950 0.1 0.0 228244 27744 ? Ss Sep28 2:25 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 19195 0.1 0.0 228244 27748 ? Ss Sep23 10:29 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 24605 0.1 0.0 228248 27752 ? Ss Sep24 8:48 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 26442 0.1 0.0 228244 27744 ? Ss 03:45 0:50 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 29714 0.1 0.0 228248 27752 ? Ss Sep25 7:06 php /var/www/html/myproj/symfony cron:aggregation --env=prod
apache 31031 0.1 0.0 228248 27752 ? Ss Sep26 5:30 php /var/www/html/myproj/symfony cron:aggregation --env=prod
I need to kill them all. And obviously I want to do it safely.
Thus, ideally I should kill them as apache using something like this:
kill 11173
The problem is that the apache userdoesn't have a shell.
So it seems the only way is escalate to root and kill the process as root. But it is not safely at all (I may kill other processes by mistake).
Has anybody got a better solution?
Thanks,
Daniele
sudo -u apache kill 11173
This should belong on http://serverfault.com I guess... but if you want to kill all processes named apache, run killall apache as root. Alternatively, change identity to your apache user with su apache and kill your processes there using kill as you did.
Related
I have done quite a bit of research, and cant find any documentation on this. I may be using the wrong terminology with the term "thread dump", so I apologize for any lack of knowledge on this topic.
I am looking for a way to take a thread dump of an Apache webserver running on an RHEL AWS instance. The Apache webserver is running on the httpd process. From my understanding, tools like jstack and jmap are specific to taking thread dumps of JVM processes only, and httpd is not compatible.
When I use ps -aux | grep apache I receive the following output of processes.
ps -aux | grep apache
ssm-user 1539 0.0 0.0 112812 960 pts/1 S+ 17:26 0:00 grep apache
apache 1554 0.0 0.2 272752 15488 ? S 16:12 0:00 /usr/sbin/httpd -DFOREGROUND
apache 1713 0.0 0.1 270376 13452 ? S 16:13 0:00 /usr/sbin/httpd -DFOREGROUND
apache 1715 0.0 0.1 270376 13452 ? S 16:13 0:00 /usr/sbin/httpd -DFOREGROUND
apache 1956 0.0 0.1 270556 14080 ? S 13:16 0:00 /usr/sbin/httpd -DFOREGROUND
apache 5700 0.0 0.2 272752 15704 ? S May22 0:00 /usr/sbin/httpd -DFOREGROUND
apache 5701 0.0 0.2 272996 16064 ? S May22 0:00 /usr/sbin/httpd -DFOREGROUND
apache 5703 0.0 0.1 270676 14368 ? S May22 0:00 /usr/sbin/httpd -DFOREGROUND
apache 5704 0.0 0.2 272720 15636 ? S May22 0:00 /usr/sbin/httpd -DFOREGROUND
apache 11441 0.0 0.2 272776 15744 ? S 04:55 0:00 /usr/sbin/httpd -DFOREGROUND
apache 11442 0.0 0.2 272800 15832 ? S 04:55 0:00 /usr/sbin/httpd -DFOREGROUND
I am also unsure why there are so many of the same process, but I wanted to figure out if its possible to take a thread dump of one of the processes before I dive into solving the duplicate processes.
Are there any tools or commands I can use to accomplish a thread dump of an httpd process?
I'm really struggling with how to find processes by name in linux. I'm sure it's probably something simple that I'm missing.
Are you looking for the command ps ?
Here an example
nabil#LAPTOP:~$ ps xua | grep python
rootwsl 327 0.0 0.1 29568 17880 ? Ss Jan30 0:02 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
rootwsl 411 0.0 0.1 108116 20740 ? Ssl Jan30 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
nabil 106387 0.0 0.0 3444 736 pts/1 S+ 23:26 0:00 grep --color=auto python
The following command
[cuser#vdev-b7-5461-4f3c-9d98-7fc3ec6 kafka]$ ps aux|grep apache
apache 3967 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3968 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3969 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3970 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3971 0.0 0.0 175276 2700 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3972 0.0 0.0 175276 2700 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3974 0.0 0.0 175412 3188 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3975 0.0 0.0 175276 2696 ? S 03:40 0:00 /usr/sbin/httpd -k start
clduser 9566 0.0 0.0 103244 844 pts/1 S+ 16:41 0:00 grep apache
There are multiple apache process running in my machine. Is there a way for me to determine the files/directory each of these process uses to run it?
Also, would like to know the ports that they are using?
[user#vdev-37-5461-4f3c-9d98-7af28dfc3ec6 kafka]$ netstat -tulpn|grep 80
(No info could be read for "-p": geteuid()=500 but you should be root.)
tcp 0 0 :::80 :::* LISTEN -
This above command shows port 80 is being used but I want to know what process is using it?
[duser#vpsq-dev-4ac0b737-5461-4f3c-9d98-7af28dfc3ec6 kafka]$ find / -iname apache 2>/dev/null
/opt/logstash/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.4.0-java/lib/org/apache
/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-elasticsearch-0.1.18-java/lib/org/apache
/opt/logstash/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.1.2-java/lib/org/apache
/home/duser/logstash-1.5.0.rc2/vendor/bundle/jruby/1.9/gems/logstash-output-elasticsearch-0.1.18-java/lib/org/apache
/home/duser/logstash-1.5.0.rc2/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.1.2-java/lib/org/apache
While working on upgrading to PHP 5.5 I've faced a problem with php-fpm.
I've created a new web node with the new PHP version and I'm signing it in on the load balancer to test it in prod. Everything works out fine until a lot of php-fpm processes gets stuck out of sudden (after ~1 hour). Hereafter I receives timeouts.
I've changed distribution from Debian to Ubuntu and upgraded to PHP 5.5. Besides that the new server is the same as before (when everything worked/works).
I've tried signing in two new web nodes and they will get stuck at the same time.
I think it can be related to sudden slow responses from database (since that's the only thing they share).
However, I would like php-fpm not to crash, so it will work when database is OK again.
To fix it now I can restart php-fpm service but that's not a solid plan.
ps aux | grep php shows me:
root 13919 0.0 0.4 423472 19736 ? Ss Dec08 0:10 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 14087 0.0 3.1 474972 127284 ? S Dec08 0:54 php-fpm: pool www
www-data 14088 0.0 2.3 446944 94956 ? S Dec08 0:50 php-fpm: pool www
www-data 14089 0.1 2.2 443816 92644 ? S Dec08 1:03 php-fpm: pool www
www-data 14090 0.0 3.0 474208 124716 ? S Dec08 0:44 php-fpm: pool www
www-data 14092 0.0 3.1 478284 129060 ? S Dec08 0:41 php-fpm: pool www
www-data 14099 0.0 2.5 459700 105224 ? S Dec08 0:14 php-fpm: pool www
www-data 14111 0.0 2.0 439876 84952 ? S Dec08 0:06 php-fpm: pool www
www-data 14114 0.0 0.4 427220 18472 ? S Dec08 0:00 php-fpm: pool www
www-data 14115 0.0 0.4 427220 18380 ? S Dec08 0:00 php-fpm: pool www
www-data 14116 0.0 0.4 427184 18936 ? S Dec08 0:00 php-fpm: pool www
www-data 14117 0.0 0.4 427204 18904 ? S Dec08 0:00 php-fpm: pool www
www-data 14118 0.0 0.4 427220 18372 ? S Dec08 0:00 php-fpm: pool www
www-data 14119 0.0 0.4 427184 18832 ? S Dec08 0:00 php-fpm: pool www
www-data 14120 0.0 0.4 427188 18960 ? S Dec08 0:00 php-fpm: pool www
www-data 14121 0.0 0.4 427220 18384 ? S Dec08 0:00 php-fpm: pool www
www-data 14122 0.0 0.4 427200 18932 ? S Dec08 0:00 php-fpm: pool www
www-data 14123 0.0 0.4 427236 18488 ? S Dec08 0:00 php-fpm: pool www
www-data 14124 0.0 0.4 427220 18392 ? S Dec08 0:00 php-fpm: pool www
www-data 14125 0.0 0.4 427220 18384 ? S Dec08 0:00 php-fpm: pool www
www-data 14126 0.0 0.4 427204 18820 ? S Dec08 0:00 php-fpm: pool www
www-data 14127 0.0 0.4 427220 18484 ? S Dec08 0:00 php-fpm: pool www
www-data 14128 0.0 0.4 427204 18920 ? S Dec08 0:00 php-fpm: pool www
www-data 14129 0.0 0.4 427188 18904 ? S Dec08 0:00 php-fpm: pool www
www-data 14130 0.0 0.4 427220 18372 ? S Dec08 0:00 php-fpm: pool www
www-data 14131 0.0 0.4 427188 18920 ? S Dec08 0:00 php-fpm: pool www
www-data 14132 0.0 0.4 427220 18372 ? S Dec08 0:00 php-fpm: pool www
www-data 14133 0.0 0.4 427204 18936 ? S Dec08 0:00 php-fpm: pool www
www-data 14134 0.0 0.4 427220 18388 ? S Dec08 0:00 php-fpm: pool www
www-data 14135 0.0 0.4 427220 18368 ? S Dec08 0:00 php-fpm: pool www
www-data 14136 0.0 0.4 427184 18936 ? S Dec08 0:00 php-fpm: pool www
As you can see 24 processes has been running for 0 seconds (htop tells me it's around 2ms). They will stay like that forever. All of them appeared at the same time.
My config:
pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
log_level = debug
user = www-data
group = www-data
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 30
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 7
pm.max_requests = 500
Also, I never see anything in the php-fpm.log (just NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful)
Anybody?
EDIT:
I have tried running both ondemand and dynamic process manager
I can't leave a comment, although you should check your log file related to php:
( /var/www/ )
( (hostname)/logs/error_log )
and
( /var/log/php5-fpm.log )
I found a bunch of long running scripts (script.php) on a server and want to kill them all.
ps aux | grep script.php
user 6270 0.1 0.1 375580 50476 ? Ss Aug20 2:18 php /path/to/script.php
user 6290 0.1 0.1 375580 50476 ? Ss 15:34 0:00 php /path/to/script.php
user 7439 0.1 0.1 375580 50476 ? Ss Aug18 2:05 php /path/to/script.php
user 8270 0.1 0.1 375580 50476 ? Ss Aug17 7:18 php /path/to/script.php
user 8548 0.1 0.1 375580 50476 ? Ss Aug15 0:15 php /path/to/script.php
user 8898 0.1 0.1 375580 50476 ? Ss Aug17 3:01 php /path/to/script.php
user 9875 0.1 0.1 375580 50476 ? Ss Aug18 2:18 php /path/to/script.php
I can kill them one at a time like so:
kill 6270
But how can I kill all of them at once?
With Linux:
pkill -f "php /path/to/script.php"
you can use the pkill command.
see http://en.wikipedia.org/wiki/Pkill and here http://www.unix.com/man-page/opensolaris/1/pkill/
Must be something like 'pkill -n script.php'