Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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
  • 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.
Independent Software Vendors: 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!


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

Get expert help—faster!

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

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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

581 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