Hi every one How to update the following codeso its can be

Hi every one , How to update the following code,so its can be scans the system process table, displaying processes that have started or ended since the last scan,(

% spy [ list of patterns] [-t secs] [-n count]

Anything enclosed in square brackets is optional. Here\'s what each field means:

list of patterns:

Is a list of patterns to look out for in the process list, possibly containing regular expressions, described briefly below. If no list is present, spy accepts all processes.

tsecs:

Tells spy how many seconds to wait between each scan of the system process table. The default value is one.

count:

Tells spy how many times the system process table should be scanned before quitting. The default value is five.

During each scan, spy produces an intermediate file containing a list of current processes in the form:

User- id process-id command

which it then compares with the list constructed during the last scan. The differences between the two lists indicate which processes have ended and which have begun since the last scan. This difference is then displayed, in a readable format together with the date and time.)

#!/bin/bash
# Setup signal traps and handle appropriately
trap \"echo; echo \'psmonitor terminated due to signal INT\'; exit\" INT
trap \"echo; echo \'psmonitor terminated due to signal HUP\'; exit\" HUP
trap \"echo; echo \'psmonitor terminated due to signal TERM\'; exit\" TERM
#

# Exist status and command path configuration
EXITNOUTIL=1 # program / utility needed to successfully execute not found
BADPARAM=2 # a bad / malformed parameter was passed to the wrapper
ENVDUMP=0
PS=/bin/ps
PSOPT=\"-e -o ruser,pid,stime,cmd \"
CLRCMD=/usr/bin/clear
DTECMD=/bin/date
SLPCMD=/bin/sleep
ECHOCMD=/bin/echo
#

# Script control configuration
TSECONDS=1
NCOUNT=10
TSEC=0
CNT=0
#

# General Variables
#

# Usage and fault identification
function help_psmonitor ()
{
   $ECHOCMD ERROR: ${1}; $ECHOCMD # This script causes the execution to halt at the first detection of a malformed command structure
   $ECHOCMD \"Usage: psmonitor <-t seconds> <-n count>\"
   $ECHOCMD \"-t seconds (>= 1 & <= 1000) : specifies the number of seconds to wait between each scan of the system process table. Default = 1.\"
   $ECHOCMD \"-n count (>= 1 & <= 1000) : specifies the number of times the system process table should be scanned before terminating. Default = 10.\"
  
   exit $BADPARAM
}

# Check to see that the utilities used by this script are where we think they are...
for util in $PS $DTECMD $SLPCMD $ECHOCMD
do
   if [ ! -x $util ]
   then
       # Realizing that this might be calling out the lack of echo, better to try than not...  
       $ECHOCMD \"ERROR: One or more of the utilities used by this script are not resident at the noted locations within the source!\" ; exit $EXITNOUTIL
   fi
done

#check to make sure that ps will handle the options we are sending to it...
$PS $PSOPT &> /dev/null

if [ $? -ne 0 ]
then
   help_psmonitor \"The \'ps\' utility referenced by this script (at the corresponding location) does not accept the parameters required!\"
fi

# start the parameter checking code...
while [ $# -gt 0 ]; do  
   case \"$1\" in
   -t|--tseconds)
       if [ $TSEC = \"1\" ]
       then
           help_psmonitor \"Duplicate flags/options supplied!\"
       fi
       TSEC=1
       shift
       case $1 in
       [1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1][0][0][0]) #1-1000
           TSECONDS=$1
       ;;
       *)
           help_psmonitor \"Missing, malformed or out of bounds sleep period supplied!\";;
       esac
   ;;
   -n|--countn)
       if [ $CNT = \"1\" ]
       then
           help_psmonitor \"Duplicate flags/options supplied!\"
       fi
       CNT=1
       shift
       case $1 in
       [1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1][0][0][0])
       NCOUNT=$1   
       ;;
       *)
           help_psmonitor \"Missing, malformed or out of bounds count supplied!\" ;;
       esac;;  
   *)
       help_psmonitor \"Malformed or nonexistent option flag!\"
   esac
   shift
done

# perform the ps calls with the requested iterations / sleep periods
while [ $NCOUNT -gt 0 ]; do
   #$CLRCMD # turned off to mimic program request specifications
   $DTECMD
   $PS $PSOPT
   $SLPCMD $TSECONDS  
   let NCOUNT-=1
$ECHOCMD   
done

Solution

The process table in Linux simply a data structure in the RAM of a computer. It holds information about the processes that are currently handled by the OS.

The process table major information is,

·         Process ID

·         Process User ID

·         Process Priority

·         Process State

·         Process resource usage

Hi every one , How to update the following code,so its can be scans the system process table, displaying processes that have started or ended since the last sca
Hi every one , How to update the following code,so its can be scans the system process table, displaying processes that have started or ended since the last sca
Hi every one , How to update the following code,so its can be scans the system process table, displaying processes that have started or ended since the last sca

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site