LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 01-23-2014, 05:25 AM   #1
robin444
LQ Newbie
 
Registered: Jan 2014
Posts: 13

Rep: Reputation: Disabled
Unhappy 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
 
Old 01-23-2014, 05:58 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,292

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
alias kil='kill -9' in an early line,

later

JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError="kill %p""?
 
Old 01-23-2014, 06:26 AM   #3
robin444
LQ Newbie
 
Registered: Jan 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by business_kid View Post
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
 
Old 01-23-2014, 06:30 AM   #4
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328

Rep: Reputation: 74
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.
Old 01-23-2014, 07:11 AM   #5
robin444
LQ Newbie
 
Registered: Jan 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by gengisdave View Post
wrote in the other thread

try JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError='kill;-9;%p'"

http://www.oracle.com/technetwork/ja...sp-140102.html
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?
 
Old 01-23-2014, 07:18 AM   #6
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328

Rep: Reputation: 74
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
 
Old 01-23-2014, 09:36 AM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
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.
 
Old 01-27-2014, 03:12 AM   #8
robin444
LQ Newbie
 
Registered: Jan 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by gengisdave View Post
wrote in the other thread

try JVM_ARGS="-Xms1536m -Xms1536m -XX:OnOutOfMemoryError='kill;-9;%p'"

http://www.oracle.com/technetwork/ja...sp-140102.html
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
 
Old 01-27-2014, 03:22 AM   #9
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328

Rep: Reputation: 74
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\""
 
Old 01-27-2014, 03:48 AM   #10
robin444
LQ Newbie
 
Registered: Jan 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by gengisdave View Post
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.
 
Old 01-27-2014, 04:12 AM   #11
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328

Rep: Reputation: 74
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.
Old 01-27-2014, 04:18 AM   #12
robin444
LQ Newbie
 
Registered: Jan 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by gengisdave View Post
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?
 
Old 01-27-2014, 04:22 AM   #13
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328

Rep: Reputation: 74
can't you move the command from jvm_args to java command line?
 
Old 01-27-2014, 04:29 AM   #14
robin444
LQ Newbie
 
Registered: Jan 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by gengisdave View Post
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.
 
Old 01-27-2014, 04:46 AM   #15
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328

Rep: Reputation: 74
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.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there software to find network issue? Possible packets dropped or similar issue xmrkite Linux - Software 7 03-17-2015 06:33 PM
Joystick and USB issue, randomly connects, also caused a mouse issue. tim.sloane Linux - Hardware 1 08-08-2012 09:05 AM
Fedora 13 Installation issue -- Unable to install multiple linux distributions ---partition issue navneethr Linux - General 6 12-22-2010 11:17 PM
Postfix issue ; Must issue a STARTTLS command first after forcing TLS sarajevo Linux - Server 3 05-14-2009 08:28 AM
Trouble mounting ipod. Hal issue and mount point issue. okos Slackware 2 05-10-2009 11:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration