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

How to get the IDs of all the Processes created by a user in LINUX OS using PERL?? My requirement is to collect all the PIDs and display them on a Administration screen.

Replies are listed 'Best First'.
Re: Getting process IDs
by ton (Friar) on Jun 19, 2002 at 08:52 UTC
    You can also take a look at Proc::ProcessTable.

    -Ton
    -----
    Be bloody, bold, and resolute; laugh to scorn
    The power of man...

      I concur strongly with the use of Proc::ProcessTable and would direct interested readers to the review of this module here and examples of usage here and here.

       

Re: Getting process IDs
by jmcnamara (Monsignor) on Jun 19, 2002 at 08:20 UTC

    Here is a simple method. Note, the pid of the perl and ps processes will also show up if $user runs the program.
    #!/usr/bin/perl -w use strict; my $user = 'root'; my @procs = `ps -U $user`; shift @procs; # Omit title line my @pids = map { (split)[0] } @procs;

    --
    John.

Re: Getting process IDs
by Zaxo (Archbishop) on Jun 19, 2002 at 08:21 UTC

    The system function '/bin/ps' has lots of options for selecting what to display:

    open PS, '-|', "/bin/ps U $username" or die $!; print while <PS>; close PS or die $!;

    After Compline,
    Zaxo