Determine PID of a batch

Hello,

I am running several batch files every 5 minutes which call perl or vbscripts. In the task manager I see several cmd.exe as well as perl.exe or cscript.exe processes as these batch files run for several minutes.
If one stalls for whatever reason, I want to be able to kill the right one. This would be possible if I know the PID of the cmd.exe  and/or perl.exe and/or cscript.exe.

I was thinking of getting the PID as the batch files starts and dropping its value in a log file.

However, I have no clue on how to get the PID of such a cmd.exe using DOS tools nor on how to get it in Perl or VBScript.

Does anyone know how to get the PID?


Marc_EngrieAsked:
Who is Participating?
 
devil_himselfConnect With a Mentor Commented:
How do I obtain the currently running batch files PID?
http://www.windowsitpro.com/Article/ArticleID/15339/15339.html

       
getpids (V0.99.002) --> http://www.scheibli.com/projects/getpids/index.html
0
 
HonorGodCommented:
0
 
HonorGodCommented:
for example, I can grep the output of "handle -a" for occurrences of "cmd.exe pid:" to find all of the cmd.exe process ids
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Marc_EngrieAuthor Commented:
Mmm !!??  Does not solve it 'problem'.

Eg: I have the batch file B1.cmd, B2.cmd, B3.cmd.
Each batch takes 4 minutes to run and I run them every 5 minutes.
When they are active, I only see cmd.exe using handle or in Task Manager. I have no clue which cmd.exe correspond with which batch file.

Therefor I was thinking of getting the PID by the process itself but how ?


0
 
HonorGodCommented:
How are the bat files started?
0
 
Adam314Commented:
In perl, the PID is the special variable $$.

You can use it like so:
print "This process has PID $$\n";
0
 
RobSampsonCommented:
Hi, you may have to change the way you execute these files, but if you execute them with VBScript's Exec method of the WScript.Shell object, you obtain the processID.  Here's an example of starting four instance of the same application, then terminating a specific one.

Set wshShell = CreateObject("WScript.Shell")
Set objExec1 = wshShell.Exec("notepad.exe")
Set objExec2 = wshShell.Exec("notepad.exe")
Set objExec3 = wshShell.Exec("notepad.exe")
Set objExec4 = wshShell.Exec("notepad.exe")

' Then to close one of them.
objExec3.Terminate


Regards,

Rob.
0
 
RobSampsonCommented:
Oh, and if you need it, the process ID can be determined via
strProcID = objExec1.ProcessID

Regards,

Rob.
0
 
Marc_EngrieAuthor Commented:
OK.

Great material but I need some time to test this. I'll be back in a few days as I need to get some other thing done right away.

I'll reply to this post asap
0
 
Marc_EngrieAuthor Commented:
I went for getpids.exe. That doing the trick for me.

And also thx forthe Perl and VBScript info on how to get the PID at run time.
0
All Courses

From novice to tech pro — start learning today.