I am using the following command to kill one java process via shell script:
pidof java|xargs kill -9 $1
What if the list of
pidof output has more than one elements? How do I kill them both with the same one command?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
First of all, check out
pkill. You can kill off any number of process given their name:
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.