|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
How to: Attach to a Running Process
This topic applies to:
Pro and Team
Does not apply
Command or commands hidden by default.
You can attach the Visual Studio debugger to any running process.
To attach to a running process
On the Debug menu, select Attach to Process. (If no project is open, select Attach to Process from the Tools menu.)
In the Attach to Process dialog box, find the program that you want to attach to from the Available Processes list.
If the program that you want to debug is running on another computer, you must first select the remote computer. (For more information, see How to: Select a Remote Machine.)
If the process is running under a different user account, select the Show processes from all users check box.
If you are connected through Remote Desktop Connection, select the Show processes in all sessions check box.
In the Attach to box, make sure that the type of code you will debug is listed. The default Automatic setting tries to determine what type of code you want to debug. If the automatic setting is not appropriate:
In the Select Code Type dialog box, click Debug these code types and select the types to debug.
The Available Processes list is displayed automatically when you open the Processes dialog box. Processes can start and stop in the background while the dialog box is open. However, the contents are not always current. You can refresh the list at any time to see the current list of processes by clicking Refresh.
You can be attached to multiple programs when you are debugging, but only one program is active in the debugger at any time. You can set the active program in the Debug Location toolbar or the Processes window. For more information, see How to: Set the Current Program.
All Debug menu execution commands affect the active program. You can break any debugged program from the Processes dialog box or break all attached programs from the Debug menu. For more information, see How to: Break Execution.
For the debugger to attach to managed code written in Visual C++, the code must emit DebuggableAttribute. You can add this to your code automatically by linking with the /ASSEMBLYDEBUG linker option.
If you try to attach to a process owned by an untrusted user account, a security warning dialog box confirmation will appear. For more information see Security Warning: Attaching to a process owned by an untrusted user can be dangerous. If the following information looks suspicious or you are unsure, do not attach to this process.
In some cases, when you debug in a Remote Desktop (Terminal Services) session, the Available Processes list will not display all available processes. On Windows Server 2003 or later versions, if you are running Visual Studio as a user who has a limited user account, the Available Processes list will not show processes that are running in Session 0, which is used for services and other server processes, including w3wp.exe. You can solve the problem by running Visual Studio under an administrator account or by running Visual Studio from the server console instead of a Terminal Services session. If neither of those workarounds is possible, a third option is to attach to the process by running vsjitdebugger.exe -p ProcessId from the Windows command line. You can determine the process id using tlist.exe. To obtain tlist.exe, download and install Debugging Tools for Windows, available at http://www.microsoft.com/whdc/devtools/debugging/default.mspx.