You might need to debug a program that is already running. You would attach to a running process if:
You wanted to debug a running server, and you did not want to stop or kill it.
You wanted to debug a running program that has a graphical user interface, and you didn’t want to restart it.
Your program was looping indefinitely, and you want to debug it without killing it.
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 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.
% 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.
If you started the process you are currently debugging with a run command, then dbx terminates that process before attaching to the new process.
If you started debugging the current process with an attach command or by specifying the process ID on the command line then dbx detaches from the current process before attaching to the new process.
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.