First of all, check out pkill
. You can kill off any number of process given their name:
pkill java
You can even use the full command with arguments as part of the search
pkill -f some_string_in_arguemnts
Secondly, your construct with xargs
will work just fine for multiple PID's as long as they are piped in as either space or newline separated numbers.
Your question is not clear, you talk about a daemon in the title, but in the body only talk about a generic process.
For a daemon there are specific means to stop it, for example in Debian you have
service daemon-name stop
or
/etc/init.d/daemon-name stop
Similar syntaxes exist for other initscript standards used in other distributions/OS.
To kill a non-daemon process, supposing it is in some way out of control, you can safely use killall
or pkill
, given that they use by default the SIGTERM
(15) signal, and any decently written application should catch and gracefully exit on receiving this signal. Take into account that these utilities could kill more that one process, if there are many with the same name.
If that do not work, you can try SIGINT
(2), then SIGHUP
(1), and as a last resort SIGKILL
(9). This last signal cannot be catched by the application, so that it cannot perform any clean-up. For this reason it should be avoided every time you can.
Both pkill
and killall
accept a signal parameter in the form -NAME
, as in
pkill -INT process-name
Best Answer
You can also kill processes by name:
Example: