Home > Archive > PERL Beginners > September 2007 > Process ID
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| How do i find out the process id of any process. When we see the task
manager in Windows, we can see the programs running in the PC. Is
there any way to know the same with perl? Does process id of a program
change each time the program is run?
| |
| Steve Bertrand 2007-09-18, 7:02 pm |
| Somu wrote:
> How do i find out the process id of any process. When we see the task
> manager in Windows, we can see the programs running in the PC. Is
> there any way to know the same with perl? Does process id of a program
> change each time the program is run?
#!/usr/bin/perl
use warnings;
use strict;
print "PID: $$\n";
--
cohiba# ./pid.pl
PID: 57355
HTH,
Steve
| |
| Chas Owens 2007-09-18, 7:02 pm |
| On 9/18/07, Somu <som.ctc@gmail.com> wrote:
> How do i find out the process id of any process.When we see the task
> manager in Windows, we can see the programs running in the PC. Is
> there any way to know the same with perl?
This is system dependent. For MS Windows machines try Win32::Process::Info*.
snip
> Does process id of a program
> change each time the program is run?
snip
This is theoretically system dependent, but the answer is "yes" on all
OSes I am aware of (because the alternative would be a very bad idea).
* http://search.cpan.org/dist/Win32-P...Process/Info.pm
| |
| shmoib@gmail.com 2007-09-23, 6:59 pm |
| On Sep 18, 5:34 pm, iaccou...@ibctech.ca (Steve Bertrand) wrote:
> Somu wrote:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> print "PID: $$\n";
>
> --
>
> cohiba# ./pid.pl
> PID: 57355
>
> HTH,
>
> Steve
actually $$ will return the current running perl module, but if you
want to get invoked program from a perl module then you will have to
list the running processes and grep in
check this: http://www.thescripts.com/forum/thread703751.html
good luck,
SHMOIB
| |
| Ken Foskey 2007-09-24, 7:01 pm |
| On Mon, 2007-09-24 at 05:13 +0530, Somu wrote:
> Thanks for the help. I did it using
>
> system "tasklist >> temp";
>
> open FH , "temp" ;
> statements..
> unlink ("temp"); #EOF
Consider this code snippet then, does this in one step. I am writing
the output to a log only you can put all the logic into the loop.
open( $process, '|-', $command ) or croak "Unable to create process
$command, $!";
while( $line = <$process> ) {
print $log $line;
}
close( $process );
--
Ken Foskey
FOSS developer
|
|
|
|
|