Sun Studio 12: Debugging a Program With dbx

Attaching dbx to a Running Process

You might need to debug a program that is already running. You would attach to a running process if:

You can attach dbx to a running program by using the program’s process_id number as an argument to the dbx debug command.

Once you have debugged the program, you can then use the detach command to take the program out from the control of dbx without terminating the process.

If you quit dbx after attaching it to a running process, dbx implicitly detaches before terminating.

To attach dbx to a program that is running independently of dbx, you can use either the attach command or the debug command.

To attach dbx to a process that is already running, type:

(dbx) debug program_name process_id


(dbx) attach process_id

You can substitute a– (dash) for the program_name; dbx automatically finds the program associated with the process ID and loads it.

For more information, see debug Command and attach Command.

If dbx is not running, start dbx by typing:

% dbx program_name process_id

After you have attached dbx to a program, the program stops executing. You can examine it as you would any program loaded into dbx. You can use any event management or process control command to debug it.

When you attach dbx to a new process while you are debugging an existing process, the following occurs:

If the process to which you are attaching dbx is stopped due to a SIGSTOP signal, SIGTSTOP signal, SIGTTIN signal, or SIGTTOUT signal, the attach succeeds with a message like the following:

dbx76: warning: Process is stopped due to signal SIGSTOP

The process is inspectable, but to resume it you need to send it a SIGCONT signal with the cont command:

(dbx) cont -sig cont

You can use runtime checking on an attached process with certain exceptions. See Using Runtime Checking on an Attached Process.