Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

get name of process with pid

by lorn (Monk)
on Nov 18, 2005 at 16:29 UTC ( [id://509861]=perlquestion: print w/replies, xml ) Need Help??

lorn has asked for the wisdom of the Perl Monks concerning the following question:

hi monks, i need to get name of process with pid, but i cant find any module to make this, what your they recommend?

PS: the O.S is Windows

Lorn -www.slackwarezine.com.br-

Replies are listed 'Best First'.
Re: get name of process with pid
by davorg (Chancellor) on Nov 18, 2005 at 16:34 UTC

    (untested)

    use Proc::ProcessTable; my $procs = Proc::ProcessTable->new; foreach ($procs->table) { if ($_->pid = $required_pid) { print $_->cmndline; last; } }
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: get name of process with pid
by puploki (Hermit) on Nov 18, 2005 at 17:18 UTC
    Use Win32::Process:Info - here's some working code that I use in some production scripts, you can tailor it to do exactly what you want, but this should give you some ideas of the syntax.
    use strict; use warnings; use Win32::Process::Info; Win32::Process::Info->Set (variant => 'WMI'); #Force to use WMI (quick +er) my $pi = Win32::Process::Info->new(); #Enumerate all the PIDs my $everest_process = undef; #For each PID, grab its name and look for everest processes for ( $pi->ListPids ) { my ($info) = $pi->GetProcInfo ($_); if ( $info->{Name} =~ /everest/gi ) { $everest_process = 1; } }
Re: get name of process with pid
by gasho (Beadle) on Nov 18, 2005 at 19:10 UTC
    @A=`ps -o pid,comm=CMD`; @B=`ps -o pid,comm=CMD -u SYSTEM`; push(@B,@A);
Re: get name of process with pid
by ickyb0d (Monk) on Nov 18, 2005 at 16:34 UTC

    A quick google found this. Program looks like it stores all current process data into a hash.

    Although it's for solaris it should still work for *nix systems. hope this helps

Re: get name of process with pid
by Perl Mouse (Chaplain) on Nov 18, 2005 at 16:35 UTC
    my $cmd = `ps -hp $PID -o %c`;
    But check the manual page of your systems ps. Different OSses have different psses using different command line switches.
    Perl --((8:>*

      Sorry people, the O.S is windows :/

      Lorn

      -www.slackwarezine.com.br-

        Looks like you might need Win32::Process::List then.

        --
        <http://dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://509861]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found