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

Hey Monks, I am trying to write a script that scans UNIX processes (that gather log data). When all the processes are done, then we compile the data and generate a report. The challenge is that PS only allows up to 80 characters. I am trying to add a unique ID to the filename. Is there a way to extract more than 80 characters out of PS. Cheers! Robert PS. Here's the code I am using to check to see whether the processes have finished or not....
#__________________________________________________________________ # # logmining'check: Check to see if the logs are still processing. + #__________________________________________________________________ sub logmining'check { my ($pid) = @_; print STDERR "CHECK: ps -ef | grep $pid.log\n\n"; #&logmining'finish (); my $ps_check = `ps -ef | grep $pid.log`; while ($ps_check =~ m|gunzip|) { sleep (60); $ps_check = `ps -ef | grep $pid.log`; if ($ps_check !~ m|gunzip|) { $ps_check = ''; &logmining'finish (); last; } } }

Replies are listed 'Best First'.
Re: How to get more than 80 characters out of PS
by Nkuvu (Priest) on Jun 28, 2005 at 20:37 UTC
    Well this is a Unix question instead of a Perl question. But depending on your flavor of Unix, you may be able to do something like my $ps_check = `ps -efww | grep $pid.log`;

    From the manpage for ps on my system (OS X 10.4.1):

    -w Use 132 columns to display information, instead of the default which is your window size. If the -w option is specified more than once, ps will use as many columns as necessary without regard for your window size.
Re: How to get more than 80 characters out of PS
by tlm (Prior) on Jun 28, 2005 at 20:38 UTC

    ps is one of the most variable of Unix commands. I doubt that what would work in my system would work in yours. For one thing, mine does not seem to have the 80-char limitation that you describe. Be that as it may, you could try setting the COLUMNS environment variable in your shell line, e.g.:

    $ps_check = `COLUMNS=300 ps -ef | grep $pid.log`;
    (Untested.)

    I agree with Nkuvu that this is much more of a Unix question than a Perl question; I think you'll likely get better advice if you asked this question in a forum devoted to your flavor of Unix.

    the lowliest monk

[OT] Re: How to get more than 80 characters out of PS
by cmeyer (Pilgrim) on Jun 28, 2005 at 21:29 UTC

    Interesting, do you usually use the single tick in place of ::? The only place that I've come across it in common use is Test::More's isn't() function (which of course has little to do with the isn:: namespace).

    Just curious ...

    -Colin.

    WHITEPAGES.COM | INC

      There's also the D'oh module.

      the lowliest monk

Re: How to get more than 80 characters out of PS
by crashtest (Curate) on Jun 29, 2005 at 03:11 UTC

    Hi rzs96,

    at work, our Sun boxes have an alternate version of ps installed under /usr/ucb. This is, I assume, the "UC Berkeley" version which supports the "double-wide" -ww switch Nkuvu refers to. When I need more than 80 characters, I run:

    /usr/ucb/ps -axwwl

    ... which gives me all the detail I need. Maybe you can check whether your installation has a similar setup. Hope this helps!

Re: How to get more than 80 characters out of PS
by fmerges (Chaplain) on Jun 28, 2005 at 21:03 UTC
Re: How to get more than 80 characters out of PS
by anonymized user 468275 (Curate) on Jun 29, 2005 at 09:03 UTC
    Why not access the unix process table directly from perl using Proc::ProcessTable?

    One world, one people