Mark
asked on
Bash script to kill all running PHP scripts?
?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thank you Gerwin for caching the typo
One more thing is that you need to be root to kill processes owned by other users, otherwise you can kill processes owned by you only.
ASKER
When I run:
ps -ef | grep -v grep | grep -i php
I am getting not only PHP scripts, but cronjobs which forked the PHP scripts ...
PHP scripts on my system are started as "php thescript.php" so I need to kill lines starting with "php " when running ps -ef
ps -ef | grep -v grep | grep -i php
I am getting not only PHP scripts, but cronjobs which forked the PHP scripts ...
PHP scripts on my system are started as "php thescript.php" so I need to kill lines starting with "php " when running ps -ef
Can you try;
ps -ef | grep -v grep | grep -i "php "
ps -ef | grep -v grep | grep -i "php "
ASKER
ps -ef | grep -v grep | grep -i "php ":
Outputs running processes containing PHP, need a list of processes that begin with "php "
Outputs running processes containing PHP, need a list of processes that begin with "php "
please give example
>> Outputs running processes containing PHP, need a list of processes that begin with "php "
Show us a list of what you're getting, so we can filter and help you further.
ps -ef | grep -v grep | grep -i " php"
The above would grep all processes in your list that start with php when the list looks like this:
But if your 'php' would be '/some/path/to/php' the above command would not work, so an example is needed from you.
Show us a list of what you're getting, so we can filter and help you further.
ps -ef | grep -v grep | grep -i " php"
The above would grep all processes in your list that start with php when the list looks like this:
rpc 588 1 0 09:57 ? 00:00:00 php thescript1.php
rpcuser 9180 1 0 16:45 ? 00:00:00 php thescript2.php
root 9477 1 0 16:45 ? 00:00:00 php thescript3.php
root 9515 1 0 16:45 ? 00:00:00 php thescript4.php
But if your 'php' would be '/some/path/to/php' the above command would not work, so an example is needed from you.
ASKER
It works, thanks
ASKER
i meant his answer:
kill -9 $(ps -ef | grep -v grep | grep -i php | awk '{ print $2 }')
kill -9 $(ps -ef | grep -v grep | grep -i php | awk '{ print $2 }')
Mark, that last comment cannot work because in ID: 40514928 you say:
So when you were getting too many lines (including cronjobs), I suggested ID: 40529563 which I tested (working) and you've accepted as answer. Now you are changing your mind of a request of attention? I do not agree.
ps -ef | grep -v grep | grep -i php
I am getting not only PHP scripts, but cronjobs which forked the PHP scripts ...
So when you were getting too many lines (including cronjobs), I suggested ID: 40529563 which I tested (working) and you've accepted as answer. Now you are changing your mind of a request of attention? I do not agree.
ASKER
In my case, it is not an issue killing the conjobs as well, I simply selected the wrong answer.
Mark, please look at the answers being suggested and you can choose the right answer from them and this could be multiple answers where you can distribute the points over the correct answers.
ASKER
I thought it originally an issue but it is not
You may try this:
kill -9 `ps -ef | grep -v grep | greo -i php | awk '{ print $2 }'`