Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
01-23-2014, 05:25 AM
|
#1
|
LQ Newbie
Registered: Jan 2014
Posts: 13
Rep: 
|
OnOutOfMemoryError issue
I am writing a shell script in which i am trying to kill a process when out of memory occurs.
My script line is
JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError="kill -9 %p""
But when i deploy or start the script i always get
an error as -9: command not found
I have tried all the kill signals to kill the process (-SIGKILL , -15 etc..) also i tried putting single quotes instead of double quotes like JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError='kill -9 %p'"
but nothing seems to work.
Please help as this is very urgent
|
|
|
01-23-2014, 05:58 AM
|
#2
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,552
|
alias kil='kill -9' in an early line,
later
JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError="kill %p""?
|
|
|
01-23-2014, 06:26 AM
|
#3
|
LQ Newbie
Registered: Jan 2014
Posts: 13
Original Poster
Rep: 
|
Quote:
Originally Posted by business_kid
alias kil='kill -9' in an early line,
later
JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError="kill %p""?
|
No i havent menioned any alias as kil
The occurance of kill -9 is only in this line
JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError="kill -9 %p""
No matter where i place kill -9 i always get the error -9 command not found
|
|
|
01-23-2014, 06:30 AM
|
#4
|
Member
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328
Rep:
|
wrote in the other thread
try JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError='kill;-9;%p'"
http://www.oracle.com/technetwork/ja...sp-140102.html
|
|
1 members found this post helpful.
|
01-23-2014, 07:11 AM
|
#5
|
LQ Newbie
Registered: Jan 2014
Posts: 13
Original Poster
Rep: 
|
Quote:
Originally Posted by gengisdave
|
That solved the error
Thanks a ton!!!!!
One more clarification Will the kill command do its job on out of memory?
Could you tell me what the issue was?
|
|
|
01-23-2014, 07:18 AM
|
#6
|
Member
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328
Rep:
|
it's a strange behaviour on command line parser, instead of spaces use semicolons to separate arguments, some people asked oracle to change this (about two years ago), but it never happened
|
|
|
01-23-2014, 09:36 AM
|
#7
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,201
|
Offhand, it strikes me that "unleashing the Finger Of God," in the form of "the killing curse that cannot be ignored," probably isn't the best thing to do in this case.
The process will run out of memory, and if it does so, it will ... vanish without a trace and without a clue. You might at the very least wish to use a signal that will force a core-dump so that you can try to figure out what the root-cause of the problem is.
JVM has very good memory-management and should never "run out of memory," unless there is (and, undoubtedly, there is...) a very serious programming bug (logic error ... design flaw) in the system that it's being called upon to run. Well, you'll never solve the problem by destroying the evidence. And the system of which this is a part will never be reliable. There's a big difference between making an inconvenient problem disappear, and solving it.
Last edited by sundialsvcs; 01-23-2014 at 09:37 AM.
|
|
|
01-27-2014, 03:12 AM
|
#8
|
LQ Newbie
Registered: Jan 2014
Posts: 13
Original Poster
Rep: 
|
Quote:
Originally Posted by gengisdave
|
i could deploy the service properly but when out of memory happened...this is the error i got
# java.lang.OutOfMemoryError: Java heap space
# -XX:OnOutOfMemoryError="'kill;-9;%p'"
# Executing /bin/sh -c "'kill"...
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
# Executing /bin/sh -c "-9"...
sh: -9: invalid option
Usage: sh [GNU long option] [option] ...
sh [GNU long option] [option] script-file ...
GNU long options:
--debug
--debugger
--dump-po-strings
--dump-strings
--help
--init-file
--login
--noediting
--noprofile
--norc
--posix
--protected
--rcfile
--rpm-requires
--restricted
--verbose
--version
--wordexp
Shell options:
-irsD or -c command or -O shopt_option (invocation only)
-abefhkmnptuvxBCHP or -o option
# Executing /bin/sh -c "23979'"...
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
Please help
|
|
|
01-27-2014, 03:22 AM
|
#9
|
Member
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328
Rep:
|
he doesn't like single quote, let's try double quote, then the only way left is using a script; as you see, he doesn't execute first arg (kill) passing the other two as argument, he treat them like 3 commands to launch
JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError=\"kill;-9;%p\""
|
|
|
01-27-2014, 03:48 AM
|
#10
|
LQ Newbie
Registered: Jan 2014
Posts: 13
Original Poster
Rep: 
|
Quote:
Originally Posted by gengisdave
he doesn't like single quote, let's try double quote, then the only way left is using a script; as you see, he doesn't execute first arg (kill) passing the other two as argument, he treat them like 3 commands to launch
JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError=\"kill;-9;%p\""
|
Error not solved  . i am still getting the same response.
yes it's taking it as 3 different arguments.
Any suggestions on how to solve this.
|
|
|
01-27-2014, 04:12 AM
|
#11
|
Member
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328
Rep:
|
Code:
import java.util.Vector;
public class MemoryEater
{
public static void main(String[] args)
{
Vector v = new Vector();
while (true)
{
byte b[] = new byte[1048576];
v.add(b);
}
}
}
$ java -XX:OnOutOfMemoryError="kill -9 %p" MemoryEater
...
#
# java.lang.OutOfMemoryError: Java heap space
# -XX:OnOutOfMemoryError="kill -9 %p"
# Executing /bin/sh -c "kill -9 28502"...
Killed
$
this work, i think the problem is with JVM_ARGS
|
|
1 members found this post helpful.
|
01-27-2014, 04:18 AM
|
#12
|
LQ Newbie
Registered: Jan 2014
Posts: 13
Original Poster
Rep: 
|
Quote:
Originally Posted by gengisdave
Code:
import java.util.Vector;
public class MemoryEater
{
public static void main(String[] args)
{
Vector v = new Vector();
while (true)
{
byte b[] = new byte[1048576];
v.add(b);
}
}
}
$ java -XX:OnOutOfMemoryError="kill -9 %p" MemoryEater
...
#
# java.lang.OutOfMemoryError: Java heap space
# -XX:OnOutOfMemoryError="kill -9 %p"
# Executing /bin/sh -c "kill -9 28502"...
Killed
$
this work, i think the problem is with JVM_ARGS
|
I wish it would work the same in shell script 
Any other way i can get this thing solved/any alternatives?
|
|
|
01-27-2014, 04:22 AM
|
#13
|
Member
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328
Rep:
|
can't you move the command from jvm_args to java command line?
|
|
|
01-27-2014, 04:29 AM
|
#14
|
LQ Newbie
Registered: Jan 2014
Posts: 13
Original Poster
Rep: 
|
Quote:
Originally Posted by gengisdave
can't you move the command from jvm_args to java command line?
|
No.My program requirement is that the JVM arguments should be setup in the script itself.
That cannot be changed. 
|
|
|
01-27-2014, 04:46 AM
|
#15
|
Member
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328
Rep:
|
hoping you use bash (don't know if it works with other shells) just create a script "killjava.sh" or whatever you want it called:
Code:
#!/bin/bash
kill -9 $PPID
you can put it in the same script directory and call it by "./killjava.sh", or put in any directory of $PATH, like /usr/local/bin and call it directly by "killjava.sh"; remember to 'chmod 755 killjava.sh' or you'll get "Permission denied"
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 06:29 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|