views:

28

answers:

2

Hi all.

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

A: 

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.

Archimedix
But I can't do su apache because apache hasn't got a shell
Daniele
Try `sudo -s -u apache` The `-s` option runs a shell, but it runs the shell specified for *you* not the one for the user 'apache'. I never run plain `su` any more.
Stephen P
On some distributions, `sudo` may need to be installed explicitly. On Debian / Ubuntu systems, it is simply named `sudo`, other distributions may have different names.
Archimedix
A: 

sudo -u apache kill 11173

Vlad Lazarenko
But I can't do su apache because apache hasn't got a shell
Daniele
@Daniele: Have you ever tried? sudo runs your shell with your environment, but with apache user's privileges.
Vlad Lazarenko
Hi Vlad. Actually that works. Thanks a lot
Daniele
You are welcome :->
Vlad Lazarenko