How to read perl process Pid from NT machine ...

How can I read a perl process PID from NT machine using a perl script that would run on unix ? An example code would make things easier for me.
JustStartedAsked:
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.

blinkie23Commented:
Can you be more specific what you'd like to do?

print $$;

is the simplest way to print the PID of the current process, but I imagine your requirements want more than this. :)
0
JustStartedAuthor Commented:
We have an issue in which perl.exe process running on the NT machine which is invoked thorugh another perl script from unix side infrequently does not get deleted. I want to write a script that would identify the Pid of this perl.exe and based on a certain criteria it would kill it. It would take care of our problem.
0
JustStartedAuthor Commented:
I want to read the PID value and assign it to a variable so that after validation of certain conditions I could delete it programatically.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

blinkie23Commented:
a couple of things.  you mentioned you had a dangling process on your NT machine that you wanted a script to kill.  this kill script would be run on the NT machine, to kill the process on that NT machine, correct?

you need someway of attaining process info for what's running on your machine.  "tasklist" is an XP way to do this, which is optionally available on NT machines if you have the resource kit apparently.  essentially, you'd parse the output of tasklist, find the task that matches "perl.exe" or whatever your sought script was, confirm it is the correct one by these validation conditions, and then issue a kill statement.

confirm that all this is correct, and your formated output of tasklist, and a perl script can be crafted fairly easily.
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
blinkie23Commented:
if you have tasklist access, you should be able to run
"tasklist" on your win machine and get an output in this
format.  you'll surely have a lot more entries.

Image Name        PID  Sess Name   Session  Memory
=====================================================
svchost.exe       500  Console        0     3,014 K
svchost.exe       502  Console        0     3,055 K
svchost.exe       504  Console        0     3,052 K
svchost.exe       510  Console        0     3,022 K
perl.exe          512  Console        0     5,933 K
svchost.exe       515  Console        0     3,001 K


i've not written perl scripts on NT machines, but it might look something like this:

#!/usr/bin/perl

my @tasklist = `tasklist`;

foreach my $entry (@tasklist){
  @entry = split(/\s+/,$entry);
  if($entry[0] =~ /perl.exe/){
    // other confirmations?
    system("kill -f $entry[1]");
    last;
  }
}


you'll definitly need more confirmations than just "perl.exe", else i have a feeling you'll end up killing your own kill script.  more info would be helpful.
0
jmcgOwnerCommented:
Nothing has happened on this question in over 8 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by blinkie23.

Please post any comments here within the next seven days. Moderators check comments here before acting on the recommendation. Experts: silence will likely be taken as assent.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
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
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.