How to quickly kill java processes in bash?
bash, kill
Solution
You can save the PIDs when you start the processes so you can use them later:
nohup ./start-gossip &
START_GOSSIP_PID=$!
nohup ./start &
START_PID=$!
nohup ./start-admin &
START_ADMIN_PID=$!
...
kill -9 $START_GOSSIP_PID
kill -9 $START_PID
kill -9 $START_ADMIN_PID
This has the advantage (over `pkill`) of not killing off any other processes that coincidentally have similar names. If you don't want to perform the kill operation from the script itself, but just want to have the PIDs handy, write them to a file (from the script):
echo $START_GOSSIP_PID > /some/path/start_gossip.pid
Or even just do this when you launch the process, rather than saving the PID to a variable:
nohup ./start-gossip &
echo $! > /some/path/start_gossip.pid
Problem
On a linux box, I have at most 3 java jars files running. How do I quickly kill all 3 with one command? Usually I would: ps ex - get the processes running then find the process ids then do: kill -9 #### #### #### Any way to shorten this process? My eyes hurts from squinting to find the process ids. My script does the following: ``` nohup ./start-gossip & nohup ./start & nohup ./start-admin & ``` Is there a way to get the process ids of each without looking it up?