pkill -f 'java.*(core|nimbus)'
I don't have a Java setup like yours but I do run a load of Django applications on my server. Similar situation in that they all look like UWSGI processes. Here's a chunk of ps aux | grep uwsgi
:
oli 7201 0.0 1.0 70324 20936 ? S 12:54 0:00 /web/venv/bin/uwsgi --include /web/django-uwsgi.ini --ini /web/asvsforms/uwsgi.ini
oli 7202 0.0 1.0 70336 20956 ? S 12:54 0:00 /web/venv/bin/uwsgi --include /web/django-uwsgi.ini --ini /web/bnc/uwsgi.ini
oli 7203 0.0 1.0 70456 21016 ? S 12:54 0:00 /web/venv/bin/uwsgi --include /web/django-uwsgi.ini --ini /web/cleanup/uwsgi.ini
oli 7204 0.0 1.0 70272 21068 ? S 12:54 0:00 /web/venv/bin/uwsgi --include /web/django-uwsgi.ini --ini /web/emwill/uwsgi.ini
oli 7205 0.0 1.3 88336 28124 ? S 12:54 0:00 /web/venv/bin/uwsgi --include /web/django-uwsgi.ini --ini /web/qi/uwsgi.ini
oli 7206 0.0 1.0 70256 20996 ? S 12:54 0:00 /web/venv/bin/uwsgi --include /web/django-uwsgi.ini --ini /web/sbaccuracy/uwsgi.ini
You can awk
that down (you don't need grep
and awk
) but jave a look at pgrep
!
$ pgrep -af 'uwsgi.*cleanup'
7203 /web/venv/bin/uwsgi --include /web/django-uwsgi.ini --ini /web/cleanup/uwsgi.ini
7217 /web/venv/bin/uwsgi --include /web/django-uwsgi.ini --ini /web/cleanup/uwsgi.ini
It's the -f
which is really required here. This expands the pattern search to the whole command line used to run something. Without it it'd only be searching the first part. The -a
is just here to output the full line.
Anyway, to kill that, we just switch to pkill
which is practically the same command. It doesn't have the same output features but that's not what it's designed for. And that leads us back to the top of the answer.
If you're going to insist on filtering ps
, please don't use ps|grep|grep|awk|egrep|awk|xargs kill
or whatever has now been suggested. It just looks silly. A single awk
can do all the filtering.
ps aux | awk '/java.*(core|nimbus)/ {print $2}'
Additionally, you can send the list to kill from directly within awk
:
ps aux | awk '/java.*(core|nimbus)/ {print $2 | kill}'
I'd still pick pgrep
and pkill
though.