Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a process and then pause it immediately?

I would like to know if there is any command or tool that can be used to start a process and then pause it immediately.

I need this function so that I can have time to attach a debugger to it. I have tried visual studio's /debugexe feature, but the behavior of the program seemed changed. So I need to find other way to attach it and debug.

Thank you.

like image 970
askalee Avatar asked Dec 18 '09 07:12

askalee


2 Answers

You can use CreateProcess() with CREATE_SUSPENDED flag. This will start the process with the main thread suspended. Then you call ResumeThread() after having attached.

like image 123
sharptooth Avatar answered Oct 18 '22 16:10

sharptooth


In your main routine insert the line:

    System.Diagnostics.Debugger.Launch();

Compile in debug mode. Run your program and it will break and prompt you to attach a debugger. If you have studio open it will ask if you want to use it to debug.

like image 2
Erg... Avatar answered Oct 18 '22 16:10

Erg...