In the purest form, you can use
server1 is actually the process name, not just somewhere in the command line - otherwise add an
pkill -f server1CommandArgument
You can test what
pkill will match and kill with the command
pgrep - which is technically almost the same. The difference it: instead of killing, it prints the PID.
Try these - list the matching PIDs:
-l lists the process name too, not only the PID:
pgrep -l server1
-f matches the command line, not only the name:
pgrep -fl server1
When you want to kill the processes that are matched by
leave out the
-l, and add a signal, if you want something else than the default SIGTERM,
pkill -9 server1
As your example uses a plain
ps command, which matches only processes on the current terminal by default, take care what is matched by your command, as
pkill are not matching only processes on the current terminal.
A side note on using
kill -9 - it is the most violent way to kill;
are you sure that's actually needed?
That may not matter, depending on what kind of program killed. But you should not do it without a good reason to a program/server that may save any data do files, writes lock files, etc. As long as a programm does not badly hang, a
kill using the default signal
-15 would do.