Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell which process I am debugging (attached to multiple processes)?

I'm debugging a windows service which has two running instances, by attaching to both instances. I am doing this because I know only one instance will hit my breakpoint, but I'd like to know which instance that is, so that I don't have to attach to both in future.

Is there a way, when attached to multiple processes, that you can tell which one has hit a breakpoint? A trial-and-error solution would be to attach one at a time and see if the breakpoint is hit, or, stop one of the services (through services.msc) and see which process ID disappears - but neither solution seems scale-able to me. Is there a more elegant way?

Thanks!

like image 589
Alec Avatar asked Jan 21 '13 16:01

Alec


People also ask

How do I debug multiple processes in Visual Studio?

To change the startup project, in Solution Explorer, right-click a different project and select Set as StartUp Project. To start debugging a project from Solution Explorer without making it the startup project, right-click the project and select Debug > Start new instance or Step into new instance.

How do I debug multiple files in Visual Studio code?

To debug multiple services at the same timeOpen the folder corresponding to your first service in VS Code. In VS Code, select File > Add Folder to Workspace…, and pick the folder corresponding to your other service.


1 Answers

You could add a watch to the following statement:

System.Diagnostics.Process.GetCurrentProcess().Id

This gives you the PID (process id) you are attached to. You can look for pids in windows task manager (Menu View->Select Columns and tick PID).

Hope this helps

like image 163
Stefano Altieri Avatar answered Oct 10 '22 08:10

Stefano Altieri