NAME

procUtils.pm - common process/program utility methods and attributes.


SYNOPSIS

    use EWS::procUtils;
    $pInfo = new EWS::procUtils(-debug => 1,
                                    -io => $baseIO);

    ###############################################################

    $pInfo->createDaemon('myLogFile')) || die "Unable to create daemon";

    @pidList = $pInfo->getMatchingPIDs;

    @pidList = $pInfo->getProgramPIDs($pInfo->programName);

    ###############################################################

    eval 
    { 
      local $SIG{ALRM} = sub {die "sigalrm"};
      local $SIG{INT}  = sub {die "sigint" };
      local $SIG{KILL} = sub {die "sigkill"};
      alarm 30;  # 30 seconds to perform task

      ...<task steps>...

      alarm 0;   # stop timer when complete.
    };

    $pResult = $pInfo->checkEval($@);

    die "alarm timeout"           if ($pResult == 1);
    die "keyboard interrupt"      if ($pResult == 2);
    die "killed"                  if ($pResult == 3);
    die "unknown/other interrupt" if ($pResult > 3);

    ###############################################################

    $SIG{INT} = \$pInfo->catchInterrupt;
    $SIG{KILL} = \$pInfo->catchKill;

    $pInfo->Interrupt(0);

    ...<perform task>...
        
    die "Interrupted" if ($pInfo->Interrupt > 0);


Description

EWS::procUtils.pm is an object oriented perl module which contains several commonly used process/program utility methods and attributes.

Methods are included to:

Exposed Attributes include:


PUBLIC METHODS


new

$pInfo = new EWS::procUtils(%parameters);

    Enter:
      %parameters = parameter hash (see below).
    Exit:
      returns a blessed reference to a new procUtils object.

    parameters are of the form:

      -arg => value

    acceptable values are:
      -debug => 1 = debug messages
          -io    => baseIO object
                  (refer to EWS::baseIO documentation).
      -trace => deprecated -- refer to -io


createDaemon

Convert this process to a daemon.

    Enter:
      $stdFile = file name to redirect std output to.
    Exit:
      result code: 0 = running as a daemon.
                   1 = no rights to root directory.
                   2 = unable to redirect STD files
                   3 = unable to fork
                   4 = unable to start new session

    Example:

      use procUtils;
      $pInfo = new EWS::procUtils(-debug=>0);
      $pInfo->createDaemon($logFileName)) || die "Unable to create daemon";


getMatchingPIDs

Return list of PIDs with same program name as this.

    Enter:
      None.
    Exit:
      @pidList if successful.
      undef if not successful.

    Note:  the returned list does not include the current process.

    Example:

      use procUtils;
      $pInfo = new EWS::procUtils(-debug=>0);
      @pidList = $pInfo->getMatchingPIDs;


getProgramPIDs

Return list of PIDs with $program name.

    Enter:
      $program = name to search schedule for.
    Exit:
      @pidList = list of pid's in list mode,
      $pidList = count of pid's in scalar mode.

      undef if not successful.

    Note:  the returned list does not include the current process.

    Example:

      use procUtils;
      $pInfo = new EWS::procUtils(-debug=>0);
      @pidList = $pInfo->getProgramPIDs('myProgramName');


resetStdError

Close current STDERR error file.

    Enter:
      none.
    Exit:
      1 if successful
      0 if unable to open STDERR


setStdError

Redirect STDERR to $errorFile.

    Enter:
      $errorFile = error file name.
    Exit:
      1 if successful
      0 if unable to open STDERR


PUBLIC SIGNAL METHODS


catchAlarm

SIGnal handler for alarm (SIGALRM)

    Enter:
      $signame = interrupt signal name
    Exit:
      none.

    Increments $interrupt to indicate interrupt has been received.

    Example:

      $SIG{ALRM} = \$pInfo->catchAlarm;

      $pInfo->Interrupt(0);  # setting $SIG will cause an interrupt, so clear it.

      alarm 30;  # set 30 seconds to perform task

      ...<perform task>...

      alarm 0;

      die "Interrupted" if ($pInfo->Interrupt > 0);


catchInterrupt

SIGnal handler for keyboard INTerrupt (SIGINT)

    Enter:
      $signame = interrupt signal name
    Exit:
      none.

    Increments $interrupt to indicate interrupt has been received.

    Example:

      $SIG{INT} = \$pInfo->catchInterrupt;

      $pInfo->Interrupt(0);  # setting $SIG will cause an interrupt, so clear it.

      ...<perform task>...

      die "Interrupted" if ($pInfo->Interrupt > 0);


catchKill

SIGnal handler for kill INTerrupt (SIGKILL)

    Enter:
      $signame = interrupt signal name
    Exit:
      none.

    Increments $interrupt to indicate interrupt has been received.

    Example:

      $SIG{KILL} = \$pInfo->catchKill;

      $pInfo->Interrupt(0);  # setting $SIG will cause an interrupt, so clear it.

      ...<perform task>...

      die "Killed" if ($pInfo->Interrupt > 0);


checkEval

Check eval result. Assumes that sigalrm, sigint and sigkill are known.

    Enter:
      $result = result to check
    Exit:
      0 = no error
      1 = sigalrm
      2 = sigint
      3 = sigkill
      4 = unknown

    Example:

      eval 
      { 
        local $SIG{ALRM} = sub {die "sigalrm"};
        local $SIG{INT}  = sub {die "sigint" };
        local $SIG{KILL} = sub {die "sigkill"};
        alarm 30;  # 30 seconds to perform task

        ...<task steps>...

        alarm 0;   # stop timer when complete.
      };

      $pResult = $pInfo->checkEval($@);

      die "alarm timeout"           if ($pResult == 1);
      die "keyboard interrupt"      if ($pResult == 2);
      die "killed"                  if ($pResult == 3);
      die "unknown/other interrupt" if ($pResult > 3);


PUBLIC ATTRIBUTES


Interrupt

Set/get internal interrupt counter. The internal interrupt counter is incremented each time a supported SIGnal occurs.

    Enter:
      $interrupt = value to set interrupt counter to
                 = undef to not change setting
    Exit:
      $interrupt = current interrupt counter value.


parseRegex

Set/get the regex used to parse file names by the getMatchingPIDs and getProgramPIDs methods. Returns current value.

    Enter:
      $regex = regex to use in parsing file names,
                    undef to not change.
    Exit:
      $regex = current regex contents.


program

Returns the running process ($$) program.

    Enter:
      None.
    Exit:
      $name = program (without execution path or type)


programName

Returns the running process ($$) program name.

    Enter:
      None.
    Exit:
      $name = program name (without execution path)


programPath

Returns the running process ($$) program path name.

    Enter:
      None.
    Exit:
      $path = program path name (without program or type)


Revision

The Revision method returns the revision number of procUtils.pm:

      $revision = $pInfo->Revision;

    Enter:
      none.
    Exit:
      current revision string.


Version

The Version method returns the version number of procUtils.pm:

      $version = $pInfo->Version;

    Enter:
      none.
    Exit:
      current version string.


Dependencies.


EWS::Trace

EWS::Trace provides a simple trace debug facility.


VERSION

Version 0.0.2 4/24/2002


AVAILABILITY

procUtils.pm is available at

  http://www.geocities.com/jaywheeler.geo/perl/Source/procUtils.pm

or as a g-zip'ed tarball at

  http://www.geocities.com/jaywheeler.geo/perl/Source/procUtils.tgz

Visit EarthWalk Software at Geocities:

  http://www.geocities.com/jaywheeler.geo


AUTHOR

Jay Wheeler, EarthWalk Software.


COPYRIGHT

procUtils.pm is copyright Š 2002. EarthWalk Software.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA