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

Posted on 2003-02-24
Medium Priority
Last Modified: 2008-03-10
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.
Question by:JustStarted
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 8011090
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. :)

Author Comment

ID: 8012061
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.

Author Comment

ID: 8012074
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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Accepted Solution

blinkie23 earned 160 total points
ID: 8013045
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.

Expert Comment

ID: 8013195
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:


my @tasklist = `tasklist`;

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

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.
LVL 20

Expert Comment

ID: 9692052
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.


EE Cleanup Volunteer

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question