We help IT Professionals succeed at work.

Sysinternals ProcDump Script

1,991 Views
Last Modified: 2012-10-11
Hello Experts,

I am having difficulty scripting ProcDump to actively monitor/attach to a process and when the process terminates, crashes, or hangs to take a Full Dump and finally continue to listen in a loop for the next instance of the processes' start for ProcDump to attach/monitor etc...

I would like for the dumps of the process (a service) to be limited to 4 dumps and overwrite the oldest dump file at each dump exceeding the 4th dump.

Below are the command line switches I am using
cd D:\ProcDump\
START ""/min "procdump" -e -h -t -ma "SomeProcess.exe" -accepteula SomeProcessDump.dmp"

http://technet.microsoft.com/en-us/sysinternals/dd996900.aspx

Thank you,
Comment
Watch Question

Author

Commented:
Below is close, however between each loop I need to terminate ProcDump without killing the process, in the Procdump command window message "Press Ctrl-C to end monitoring without terminating the process" seems to be my only option.  How do I 'pipe' in Ctrl-C so at each loop so I can then start a new 'ProcDump/someprocess attachment' to eliminate many copies of ProcDump/someprocess attachment(s) from  running?

Thanks,

@echo off
setlocal

set pd=D:\procdump.exe
set dest=D:\procdump\SomeProcessDumpDirectory
set wait=60
set keep=4
 
:_loop
set shortdatetime=%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%

cd D:\ProcDump\
START ""/min "procdump" -e -h -ma -n 20 "SomeProcessDump*.dmp" -accepteula %dest%\SomeProcessDump.dmp"
ping localhost -n %wait% > NUL 2>&1
ren "%dest%\SomeProcessServiceDump*.dmp" "%shortdatetime%.dmp"

set count=0
 
for /f "tokens=*" %%G in ('dir "%dest%\*SomeProcessServiceDump*.dmp" /a:-d /b /o:-d') do (
 set oldest=%dest%\%%G
 set /a count+=1
)
 
if %count% GTR %keep% del "%oldest%"
goto :_loop
 
if %count% GTR %keep% del "%oldest%"
goto :_loop

Author

Commented:
Someone will have an easy 500 points soon... (i think anyway if piping in a command is easy to do or if I don't figure it out first :) )

From the link below it appears in addition to piping in Ctrl-C that I will have to create another bat script to call the bat script above with the CMD /c option to prevent the above bat script from also exiting when the piped Ctrl-C is sent at each loop.

http://ss64.com/nt/cmd.html
If one batch file CALLs another batch file CTRL-C will exit both batch scripts.
If CMD /c is used to call one batch file from another then CTRL-C will cause only one of the batch scripts to terminate.

Author

Commented:
Adding below seems a valid option.  Now I will test & verify.

:holding
ping localhost -n %wait% > NUL 2>&1
FIND /I /V "SomeProcess.exe"
IF NOT ERRORLEVEL 1 GOTO :wait
IF ERRORLEVEL 1 goto :proceed

:wait
ping localhost -n %wait% > NUL 2>&1
FIND /I /V "SomeProcess.exe"
IF NOT ERRORLEVEL 1 GOTO :holding
IF ERRORLEVEL 1 goto :proceed

:proceed
if %count% GTR %keep% del "%oldest%"
goto :_loop
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
No one else helped and it was an acceptable solution to what I had originally requested

Commented:
Rick,

Thanks for sharing your findings.

Cheers,
Rene

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.