3

I sometimes use a timer to call System.exit in order to kill my throw-away code snippet after few seconds, which is quite useful in case it eats 100% CPU and Windows gets irresponsible because of this. It's quite handy, except in case I start it in debugger. In debugger I'd like to disable it automatically, otherwise I forget it and my debugged process gets killed. Can I find out if a process was started in debugger?

Note: I know I should not use this for anything serious. I'm not going to.

maaartinus
  • 44,714
  • 32
  • 161
  • 320
  • possible duplicate of [How to find out if "debug mode" is enabled](http://stackoverflow.com/questions/3776204/how-to-find-out-if-debug-mode-is-enabled) – Joachim Sauer Feb 09 '11 at 12:45
  • You're right - however, I could find it. So probably it's better not to close this question. I'd never figure out the wording **debug mode enabled**. – maaartinus Feb 09 '11 at 14:44

1 Answers1

5

Check here. This checks for the JDWP.

Basically:

boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().
    getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
Community
  • 1
  • 1