Kill only one Java process
up vote
14
down vote
favorite
I usually run few Java applications, one for server running locally and other for some IDE like NetBeans. And from time to time, after lots of redeployments, my server get stuck on OutOfMemoryException so I need to kill Java process in order to reboot.
So I do pkill -9 java
but this also kills my running IDE which I don't want to. So how do I kill only application linked to running server and not the other ones?I assume that they all are running under same process but there has to be some way how to distuingish them.
process java kill
add a comment |
up vote
14
down vote
favorite
I usually run few Java applications, one for server running locally and other for some IDE like NetBeans. And from time to time, after lots of redeployments, my server get stuck on OutOfMemoryException so I need to kill Java process in order to reboot.
So I do pkill -9 java
but this also kills my running IDE which I don't want to. So how do I kill only application linked to running server and not the other ones?I assume that they all are running under same process but there has to be some way how to distuingish them.
process java kill
2
look at your process table (viatop
orps
) and choose the right one and kill it by PID (kill -9 PID_number).
– rush
Feb 13 '13 at 8:25
Oh yes, I can see that now. So I just need to kill process with rightPID
. Thanks a lot
– Petr Mensik
Feb 13 '13 at 8:27
add a comment |
up vote
14
down vote
favorite
up vote
14
down vote
favorite
I usually run few Java applications, one for server running locally and other for some IDE like NetBeans. And from time to time, after lots of redeployments, my server get stuck on OutOfMemoryException so I need to kill Java process in order to reboot.
So I do pkill -9 java
but this also kills my running IDE which I don't want to. So how do I kill only application linked to running server and not the other ones?I assume that they all are running under same process but there has to be some way how to distuingish them.
process java kill
I usually run few Java applications, one for server running locally and other for some IDE like NetBeans. And from time to time, after lots of redeployments, my server get stuck on OutOfMemoryException so I need to kill Java process in order to reboot.
So I do pkill -9 java
but this also kills my running IDE which I don't want to. So how do I kill only application linked to running server and not the other ones?I assume that they all are running under same process but there has to be some way how to distuingish them.
process java kill
process java kill
asked Feb 13 '13 at 8:17
Petr Mensik
2913518
2913518
2
look at your process table (viatop
orps
) and choose the right one and kill it by PID (kill -9 PID_number).
– rush
Feb 13 '13 at 8:25
Oh yes, I can see that now. So I just need to kill process with rightPID
. Thanks a lot
– Petr Mensik
Feb 13 '13 at 8:27
add a comment |
2
look at your process table (viatop
orps
) and choose the right one and kill it by PID (kill -9 PID_number).
– rush
Feb 13 '13 at 8:25
Oh yes, I can see that now. So I just need to kill process with rightPID
. Thanks a lot
– Petr Mensik
Feb 13 '13 at 8:27
2
2
look at your process table (via
top
or ps
) and choose the right one and kill it by PID (kill -9 PID_number).– rush
Feb 13 '13 at 8:25
look at your process table (via
top
or ps
) and choose the right one and kill it by PID (kill -9 PID_number).– rush
Feb 13 '13 at 8:25
Oh yes, I can see that now. So I just need to kill process with right
PID
. Thanks a lot– Petr Mensik
Feb 13 '13 at 8:27
Oh yes, I can see that now. So I just need to kill process with right
PID
. Thanks a lot– Petr Mensik
Feb 13 '13 at 8:27
add a comment |
5 Answers
5
active
oldest
votes
up vote
19
down vote
accepted
For killing a process that is associated with multiple processes, you need to kill that by using process id associated with that process.
To get the process id of that java process run
ps -A |grep java
output of this command will give the list of java processes running on your system. Note down Process ID (PID) of that process whom you want to kill and run
kill -9 PID
If you want to kill ALL java processes by one commandps ax | grep java | grep -v 'grep' | cut -d '?' -f1 | xargs kill -9
– Andrii Karaivanskyi
Oct 26 '17 at 17:09
add a comment |
up vote
8
down vote
IMO the best solution is:
pkill -9 -f <nameOfYourJavaAplication>
add a comment |
up vote
5
down vote
Instead of using ps
and grep
, you can use ps
's -C
flag to select all commands listed with the name 'java'. You may also want to use ps
's -f
flag to print the full command name of each listed process. That way, you can see what each java process is actually doing. Here is the command in full: ps -fC java
.
You could also use pgrep
to list all java processes. pgrep -a java
will return the PID and full command line of each java process.
Once you have the PID of the command you wish to kill, use kill
with the -9
(SIGKILL) flag and the PID of the java process you wish to kill. Java doesn't always stop when it receives a 'SIGTERM' signal (processes are allowed to handle 'SIGTERM'), so sending it the 'SIGKILL' signal, which makes init kill the program without warning it first, is often necessary.
For example, if ps -fC java
returns
UID PID PPID C STIME TTY TIME CMD
jeff 9014 8890 0 08:51 pts/0 00:00:00 java IDE
jeff 11775 8890 6 08:59 pts/0 00:00:00 java TestProgram
or psgrep -a java
returns
9014 java IDE
11775 java TestProgram
and you wish to kill java TestProgram
, you should run kill -9 11775
.
add a comment |
up vote
0
down vote
jps
and jcmd
are tools specialized in displaying only Java processes information and PIDs.
You can explore their options for a more detailed output.
Those only list themselves on my computer.
– Alexis Wilke
Dec 1 at 3:09
Then, are you sure there are other Java processes running ?!
– Muhammad Gelbana
Dec 1 at 20:34
Yes. I had Cassandra or Elassadra running when testing your command.
– Alexis Wilke
Dec 1 at 22:36
add a comment |
up vote
0
down vote
Here is a script one can use to automate the process.
Replace the <PROCESS_NAME>
part with whatever java is executing.
#!/bin/sh
process=`ps -ef | grep -v awk | awk -e '/java.*<PROCESS_NAME>/ { print $2 }'`
kill ${process}
Note: I did not put the -9
. I should not be required unless you capture signals and SIGTERM
(the default) fails. I would also suggest you use the signal name which makes it easier to read:
kill -TERM ${process}
WARNING
Before executing the kill ...
make sure that the $process
variable gets set as expected. The ps -ef
may different between Unices so awk
may need to print a different parameter.
Note
The <PROCESS_NAME>
could be changed into a variable. Just remember that if you have to type it on your command line each time, you are likely to make mistakes once in a while. I find it easier to have multiple copy of the script with the correct name.
Also important: notice the single quotes for the awk
script. That means you need to close and reopen the string with the variable in between. Something like this should work (untested):
process=`ps -ef | grep -v awk | awk -e '/java.*'"${PROCESS_NAME}"'/ { print $2 }'`
add a comment |
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
19
down vote
accepted
For killing a process that is associated with multiple processes, you need to kill that by using process id associated with that process.
To get the process id of that java process run
ps -A |grep java
output of this command will give the list of java processes running on your system. Note down Process ID (PID) of that process whom you want to kill and run
kill -9 PID
If you want to kill ALL java processes by one commandps ax | grep java | grep -v 'grep' | cut -d '?' -f1 | xargs kill -9
– Andrii Karaivanskyi
Oct 26 '17 at 17:09
add a comment |
up vote
19
down vote
accepted
For killing a process that is associated with multiple processes, you need to kill that by using process id associated with that process.
To get the process id of that java process run
ps -A |grep java
output of this command will give the list of java processes running on your system. Note down Process ID (PID) of that process whom you want to kill and run
kill -9 PID
If you want to kill ALL java processes by one commandps ax | grep java | grep -v 'grep' | cut -d '?' -f1 | xargs kill -9
– Andrii Karaivanskyi
Oct 26 '17 at 17:09
add a comment |
up vote
19
down vote
accepted
up vote
19
down vote
accepted
For killing a process that is associated with multiple processes, you need to kill that by using process id associated with that process.
To get the process id of that java process run
ps -A |grep java
output of this command will give the list of java processes running on your system. Note down Process ID (PID) of that process whom you want to kill and run
kill -9 PID
For killing a process that is associated with multiple processes, you need to kill that by using process id associated with that process.
To get the process id of that java process run
ps -A |grep java
output of this command will give the list of java processes running on your system. Note down Process ID (PID) of that process whom you want to kill and run
kill -9 PID
edited Feb 13 '13 at 8:39
manatwork
21.5k38284
21.5k38284
answered Feb 13 '13 at 8:36
P4cK3tHuNt3R
51137
51137
If you want to kill ALL java processes by one commandps ax | grep java | grep -v 'grep' | cut -d '?' -f1 | xargs kill -9
– Andrii Karaivanskyi
Oct 26 '17 at 17:09
add a comment |
If you want to kill ALL java processes by one commandps ax | grep java | grep -v 'grep' | cut -d '?' -f1 | xargs kill -9
– Andrii Karaivanskyi
Oct 26 '17 at 17:09
If you want to kill ALL java processes by one command
ps ax | grep java | grep -v 'grep' | cut -d '?' -f1 | xargs kill -9
– Andrii Karaivanskyi
Oct 26 '17 at 17:09
If you want to kill ALL java processes by one command
ps ax | grep java | grep -v 'grep' | cut -d '?' -f1 | xargs kill -9
– Andrii Karaivanskyi
Oct 26 '17 at 17:09
add a comment |
up vote
8
down vote
IMO the best solution is:
pkill -9 -f <nameOfYourJavaAplication>
add a comment |
up vote
8
down vote
IMO the best solution is:
pkill -9 -f <nameOfYourJavaAplication>
add a comment |
up vote
8
down vote
up vote
8
down vote
IMO the best solution is:
pkill -9 -f <nameOfYourJavaAplication>
IMO the best solution is:
pkill -9 -f <nameOfYourJavaAplication>
answered Feb 13 '13 at 14:52
Marek R
1885
1885
add a comment |
add a comment |
up vote
5
down vote
Instead of using ps
and grep
, you can use ps
's -C
flag to select all commands listed with the name 'java'. You may also want to use ps
's -f
flag to print the full command name of each listed process. That way, you can see what each java process is actually doing. Here is the command in full: ps -fC java
.
You could also use pgrep
to list all java processes. pgrep -a java
will return the PID and full command line of each java process.
Once you have the PID of the command you wish to kill, use kill
with the -9
(SIGKILL) flag and the PID of the java process you wish to kill. Java doesn't always stop when it receives a 'SIGTERM' signal (processes are allowed to handle 'SIGTERM'), so sending it the 'SIGKILL' signal, which makes init kill the program without warning it first, is often necessary.
For example, if ps -fC java
returns
UID PID PPID C STIME TTY TIME CMD
jeff 9014 8890 0 08:51 pts/0 00:00:00 java IDE
jeff 11775 8890 6 08:59 pts/0 00:00:00 java TestProgram
or psgrep -a java
returns
9014 java IDE
11775 java TestProgram
and you wish to kill java TestProgram
, you should run kill -9 11775
.
add a comment |
up vote
5
down vote
Instead of using ps
and grep
, you can use ps
's -C
flag to select all commands listed with the name 'java'. You may also want to use ps
's -f
flag to print the full command name of each listed process. That way, you can see what each java process is actually doing. Here is the command in full: ps -fC java
.
You could also use pgrep
to list all java processes. pgrep -a java
will return the PID and full command line of each java process.
Once you have the PID of the command you wish to kill, use kill
with the -9
(SIGKILL) flag and the PID of the java process you wish to kill. Java doesn't always stop when it receives a 'SIGTERM' signal (processes are allowed to handle 'SIGTERM'), so sending it the 'SIGKILL' signal, which makes init kill the program without warning it first, is often necessary.
For example, if ps -fC java
returns
UID PID PPID C STIME TTY TIME CMD
jeff 9014 8890 0 08:51 pts/0 00:00:00 java IDE
jeff 11775 8890 6 08:59 pts/0 00:00:00 java TestProgram
or psgrep -a java
returns
9014 java IDE
11775 java TestProgram
and you wish to kill java TestProgram
, you should run kill -9 11775
.
add a comment |
up vote
5
down vote
up vote
5
down vote
Instead of using ps
and grep
, you can use ps
's -C
flag to select all commands listed with the name 'java'. You may also want to use ps
's -f
flag to print the full command name of each listed process. That way, you can see what each java process is actually doing. Here is the command in full: ps -fC java
.
You could also use pgrep
to list all java processes. pgrep -a java
will return the PID and full command line of each java process.
Once you have the PID of the command you wish to kill, use kill
with the -9
(SIGKILL) flag and the PID of the java process you wish to kill. Java doesn't always stop when it receives a 'SIGTERM' signal (processes are allowed to handle 'SIGTERM'), so sending it the 'SIGKILL' signal, which makes init kill the program without warning it first, is often necessary.
For example, if ps -fC java
returns
UID PID PPID C STIME TTY TIME CMD
jeff 9014 8890 0 08:51 pts/0 00:00:00 java IDE
jeff 11775 8890 6 08:59 pts/0 00:00:00 java TestProgram
or psgrep -a java
returns
9014 java IDE
11775 java TestProgram
and you wish to kill java TestProgram
, you should run kill -9 11775
.
Instead of using ps
and grep
, you can use ps
's -C
flag to select all commands listed with the name 'java'. You may also want to use ps
's -f
flag to print the full command name of each listed process. That way, you can see what each java process is actually doing. Here is the command in full: ps -fC java
.
You could also use pgrep
to list all java processes. pgrep -a java
will return the PID and full command line of each java process.
Once you have the PID of the command you wish to kill, use kill
with the -9
(SIGKILL) flag and the PID of the java process you wish to kill. Java doesn't always stop when it receives a 'SIGTERM' signal (processes are allowed to handle 'SIGTERM'), so sending it the 'SIGKILL' signal, which makes init kill the program without warning it first, is often necessary.
For example, if ps -fC java
returns
UID PID PPID C STIME TTY TIME CMD
jeff 9014 8890 0 08:51 pts/0 00:00:00 java IDE
jeff 11775 8890 6 08:59 pts/0 00:00:00 java TestProgram
or psgrep -a java
returns
9014 java IDE
11775 java TestProgram
and you wish to kill java TestProgram
, you should run kill -9 11775
.
edited Feb 13 '13 at 14:10
answered Feb 13 '13 at 13:49
user26112
add a comment |
add a comment |
up vote
0
down vote
jps
and jcmd
are tools specialized in displaying only Java processes information and PIDs.
You can explore their options for a more detailed output.
Those only list themselves on my computer.
– Alexis Wilke
Dec 1 at 3:09
Then, are you sure there are other Java processes running ?!
– Muhammad Gelbana
Dec 1 at 20:34
Yes. I had Cassandra or Elassadra running when testing your command.
– Alexis Wilke
Dec 1 at 22:36
add a comment |
up vote
0
down vote
jps
and jcmd
are tools specialized in displaying only Java processes information and PIDs.
You can explore their options for a more detailed output.
Those only list themselves on my computer.
– Alexis Wilke
Dec 1 at 3:09
Then, are you sure there are other Java processes running ?!
– Muhammad Gelbana
Dec 1 at 20:34
Yes. I had Cassandra or Elassadra running when testing your command.
– Alexis Wilke
Dec 1 at 22:36
add a comment |
up vote
0
down vote
up vote
0
down vote
jps
and jcmd
are tools specialized in displaying only Java processes information and PIDs.
You can explore their options for a more detailed output.
jps
and jcmd
are tools specialized in displaying only Java processes information and PIDs.
You can explore their options for a more detailed output.
answered Oct 10 at 17:00
Muhammad Gelbana
58051122
58051122
Those only list themselves on my computer.
– Alexis Wilke
Dec 1 at 3:09
Then, are you sure there are other Java processes running ?!
– Muhammad Gelbana
Dec 1 at 20:34
Yes. I had Cassandra or Elassadra running when testing your command.
– Alexis Wilke
Dec 1 at 22:36
add a comment |
Those only list themselves on my computer.
– Alexis Wilke
Dec 1 at 3:09
Then, are you sure there are other Java processes running ?!
– Muhammad Gelbana
Dec 1 at 20:34
Yes. I had Cassandra or Elassadra running when testing your command.
– Alexis Wilke
Dec 1 at 22:36
Those only list themselves on my computer.
– Alexis Wilke
Dec 1 at 3:09
Those only list themselves on my computer.
– Alexis Wilke
Dec 1 at 3:09
Then, are you sure there are other Java processes running ?!
– Muhammad Gelbana
Dec 1 at 20:34
Then, are you sure there are other Java processes running ?!
– Muhammad Gelbana
Dec 1 at 20:34
Yes. I had Cassandra or Elassadra running when testing your command.
– Alexis Wilke
Dec 1 at 22:36
Yes. I had Cassandra or Elassadra running when testing your command.
– Alexis Wilke
Dec 1 at 22:36
add a comment |
up vote
0
down vote
Here is a script one can use to automate the process.
Replace the <PROCESS_NAME>
part with whatever java is executing.
#!/bin/sh
process=`ps -ef | grep -v awk | awk -e '/java.*<PROCESS_NAME>/ { print $2 }'`
kill ${process}
Note: I did not put the -9
. I should not be required unless you capture signals and SIGTERM
(the default) fails. I would also suggest you use the signal name which makes it easier to read:
kill -TERM ${process}
WARNING
Before executing the kill ...
make sure that the $process
variable gets set as expected. The ps -ef
may different between Unices so awk
may need to print a different parameter.
Note
The <PROCESS_NAME>
could be changed into a variable. Just remember that if you have to type it on your command line each time, you are likely to make mistakes once in a while. I find it easier to have multiple copy of the script with the correct name.
Also important: notice the single quotes for the awk
script. That means you need to close and reopen the string with the variable in between. Something like this should work (untested):
process=`ps -ef | grep -v awk | awk -e '/java.*'"${PROCESS_NAME}"'/ { print $2 }'`
add a comment |
up vote
0
down vote
Here is a script one can use to automate the process.
Replace the <PROCESS_NAME>
part with whatever java is executing.
#!/bin/sh
process=`ps -ef | grep -v awk | awk -e '/java.*<PROCESS_NAME>/ { print $2 }'`
kill ${process}
Note: I did not put the -9
. I should not be required unless you capture signals and SIGTERM
(the default) fails. I would also suggest you use the signal name which makes it easier to read:
kill -TERM ${process}
WARNING
Before executing the kill ...
make sure that the $process
variable gets set as expected. The ps -ef
may different between Unices so awk
may need to print a different parameter.
Note
The <PROCESS_NAME>
could be changed into a variable. Just remember that if you have to type it on your command line each time, you are likely to make mistakes once in a while. I find it easier to have multiple copy of the script with the correct name.
Also important: notice the single quotes for the awk
script. That means you need to close and reopen the string with the variable in between. Something like this should work (untested):
process=`ps -ef | grep -v awk | awk -e '/java.*'"${PROCESS_NAME}"'/ { print $2 }'`
add a comment |
up vote
0
down vote
up vote
0
down vote
Here is a script one can use to automate the process.
Replace the <PROCESS_NAME>
part with whatever java is executing.
#!/bin/sh
process=`ps -ef | grep -v awk | awk -e '/java.*<PROCESS_NAME>/ { print $2 }'`
kill ${process}
Note: I did not put the -9
. I should not be required unless you capture signals and SIGTERM
(the default) fails. I would also suggest you use the signal name which makes it easier to read:
kill -TERM ${process}
WARNING
Before executing the kill ...
make sure that the $process
variable gets set as expected. The ps -ef
may different between Unices so awk
may need to print a different parameter.
Note
The <PROCESS_NAME>
could be changed into a variable. Just remember that if you have to type it on your command line each time, you are likely to make mistakes once in a while. I find it easier to have multiple copy of the script with the correct name.
Also important: notice the single quotes for the awk
script. That means you need to close and reopen the string with the variable in between. Something like this should work (untested):
process=`ps -ef | grep -v awk | awk -e '/java.*'"${PROCESS_NAME}"'/ { print $2 }'`
Here is a script one can use to automate the process.
Replace the <PROCESS_NAME>
part with whatever java is executing.
#!/bin/sh
process=`ps -ef | grep -v awk | awk -e '/java.*<PROCESS_NAME>/ { print $2 }'`
kill ${process}
Note: I did not put the -9
. I should not be required unless you capture signals and SIGTERM
(the default) fails. I would also suggest you use the signal name which makes it easier to read:
kill -TERM ${process}
WARNING
Before executing the kill ...
make sure that the $process
variable gets set as expected. The ps -ef
may different between Unices so awk
may need to print a different parameter.
Note
The <PROCESS_NAME>
could be changed into a variable. Just remember that if you have to type it on your command line each time, you are likely to make mistakes once in a while. I find it easier to have multiple copy of the script with the correct name.
Also important: notice the single quotes for the awk
script. That means you need to close and reopen the string with the variable in between. Something like this should work (untested):
process=`ps -ef | grep -v awk | awk -e '/java.*'"${PROCESS_NAME}"'/ { print $2 }'`
answered Dec 1 at 3:27
Alexis Wilke
939615
939615
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f64623%2fkill-only-one-java-process%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
look at your process table (via
top
orps
) and choose the right one and kill it by PID (kill -9 PID_number).– rush
Feb 13 '13 at 8:25
Oh yes, I can see that now. So I just need to kill process with right
PID
. Thanks a lot– Petr Mensik
Feb 13 '13 at 8:27