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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HonorGodSoftware EngineerCommented:
0
HonorGodSoftware EngineerCommented:
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
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

HonorGodSoftware EngineerCommented:
How are the bat files started?
0
devil_himselfCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.