JustStarted
asked on
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.
ASKER
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.
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
"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.
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
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
print $$;
is the simplest way to print the PID of the current process, but I imagine your requirements want more than this. :)