Attaching to a running Java Virtual Machine
Important:
You can only attach to a Java Virtual Machine if you are debugging an interpreted Java
program. For High Performance Compiled (HPC) Java programs, you must attach to a running
process. See the related topic below on how to attach to a running process.
You can attach to an already running Java Virtual Machine (JVM) if you run your Java
application with the java_g -debug command. When you start your application
with the java_g -debug command, an agent password is displayed. Take note of
this password because it will be needed to attach to the running JVM.
Once your application is running and you have the agent password, you can connect to
the JVM from the debugger user interface or from the command line.
To attach to a running JVM from the debugger user interface:
- Select Attach JVM from the File menu. The Attach to
Java Virtual Machine dialog appears.
- Select the type of connection for the attach from the dialog.
- Enter the required parameters for the type of connection.
- Click Attach to attach to the JVM and dismiss the dialog.
To attach to a running JVM from the command line:
- Start the debug engine daemon for the host JVM using the irmtdbgj command
with the JVM attach parameters. If you are debugging remotely, remember to use the engine
daemon parameters as well. For example:
irmtdbgj -qhost=workstation_id -quiport=8001 -host=hostname -password=agent_password
Where:
- workstation_id is the TCP/IP name or TCP/IP address of the
workstation running the debugger interface daemon.
- hostname is the TCP/IP name or TCP/IP address of the machine
running the JVM. If the host running the JVM and the machine running the debug engine are
the same, use localhost as the hostname.
- agent_password is the password printed when you start your Java
program using the java_g -debug command.
- Start the debugger interface in attach mode. Use a process_id of 0
for the -a parameter when attaching to a JVM. If you are debugging remotely,
remember to use the remote debug parameters as well. For example:
idebug -a0 -qhost=remotehost -qport=8001
![[Related Concepts]](../images/ngrelc.gif)

When to attach


Attaching to a local running process

Starting the debugger for local
debugging

Starting the debugger for remote
debugging

idebug command
irmtdbgj
command