0

This question already has an answer here:

How to write a script that kills a java process?

From console it looks like

root@ubuntu-s-1vcpu-1gb-ams3-01:~# lsof -i tcp:8080
COMMAND  PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
java    9657 root   26u  IPv6 4694148      0t0  TCP *:http-alt (LISTEN)
root@ubuntu-s-1vcpu-1gb-ams3-01:~# kill 9657

How should it be implemented in .sh file?

marked as duplicate by Ravexina, Rinzwind, George Udosen, user535733, Sergiy Kolodyazhnyy bash Aug 19 '18 at 23:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

-2

Just use the killall command. That should work. Like this:

killall java

(Just in case you don't know how to create a executable .sh file (It's not quite clear): A .sh file should begin with a shebang, something like

#!/bin/sh

After that, you just write commands like you would in a terminal, separated into lines. Then you run

chmod +x <insert filename>

and are able to execute the .sh file just fine. killall should be no exception

  • 1
    This will kill all Java processes, not just one in particular. -1 – David Foerster Aug 19 '18 at 23:24
  • kill all java process is too resolved my issue – Valentyn Hruzytskyi Aug 20 '18 at 21:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.