19

If I start a java process in a cygwin console, and then launch visualVm, the later cannot see the former.

If I start the same process in a Dos console visualvm sees it fine. I am in jdk1.6.0_25. This happens both in win7 32b, and in win7 64b with a 64b jvm.

Anyone can think of an explanation/workaround?

Persimmonium
  • 15,593
  • 11
  • 47
  • 78
  • are both from the same system user? – FlorianOver Jul 13 '11 at 10:06
  • Any parameter? What happens if you start the visualVM from cygwin? (What happens if you explicitly reference it via jmx-connection? Right mouse click "Add JMX connection") – FlorianOver Jul 13 '11 at 11:39
  • @FlorianOver: Good point. I have the same problem, but if I start JVisualVM from inside Cygwin, I can see the Java proc launched from Cygwin. However, I don't see Java procs launched outside Cygwin. Strange... – sleske Aug 24 '11 at 13:37
  • 1
    That's caused by the fact that Java uses a directory (hsperfdata_USERNAME) to save information consumed then by visualvm. Usually it's in %userprofile%/AppData/Local/Temp. For some reason, under cygwin, Java and visualvm looks for that dir in /tmp. Cannot figure out how it Java knows about /tmp. – Bartosz Klimek May 09 '12 at 14:59
  • Oh wow! For many years I was thinking it was *Gradle* that was somehow making launched java processes private from debugging. (Versus running from an IDE.) I would never have guessed it was cygwin / temp directory issues. – Luke Usherwood Oct 24 '19 at 12:31
  • @BartoszKlimek looks like all Java processes (debugger and debuggee) just go via the $TMP environment variable -- this is the key difference in the cygwin environment – Luke Usherwood Oct 24 '19 at 12:40

4 Answers4

13

I fixed the problem by running VisualVM from within Cygwin. If you prefer not to profile using a remote JMX connection, you can run both VisualVM and your Java program using Cygwin:

Open the Cygwin Console window, navigate to visual_vm.exe and run that file from within the Cygwin environment.

seanhodges
  • 17,426
  • 15
  • 71
  • 93
4

I had the same problem. The vm was not shown automatically but I was able to connect via "Add JMX Connection", using hostname and jmx.remote.port...

On VisualVM go to File -> Add JMX Connection

localhost:3333

Add vm parameter at startup e.g.:

 -Dcom.sun.management.jmxremote.port=3333
 -Dcom.sun.management.jmxremote.ssl=false
 -Dcom.sun.management.jmxremote.authenticate=false
Frankie
  • 24,627
  • 10
  • 79
  • 121
Laertes
  • 334
  • 1
  • 6
2

VisualVM can automatically detect local applications running under the same user. So one explanation can be that cygwin process is running under the different user. Make sure that both VisualVM and monitored application is running under JDK 6 update 25. JDK 6 update 25 has a fix for the following JDK bug #6938627, which can affect your case.

Tomas Hurka
  • 6,723
  • 29
  • 38
0

The opposite approach to @seanhodges answer is to launch the application to debug with a modified environment, pointing it back to your Windows User Temp directory

For example if you normally do:

    ./gradlew run

And say your TEMP directory on Windows (according to your User environment variables) is:

    T:\Temp

You can do one of these instead:

    TMP=T:\\Temp ./gradlew run

    TMP=/cygdrive/t/Temp ./gradlew run

(they both seem to work)

Luke Usherwood
  • 3,082
  • 1
  • 28
  • 35