Announcement

Collapse
No announcement yet.

Process Statics from Process Name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Process Statics from Process Name

    I Want to capture the current process details of JavaServer1 and JavaServer2 for 10Hr into outputlog in desire location. but every after 4 Hrs application server getting restarted as functionality.

    I am facing problem while using prstat command to get the process statics with "-p" option.

    for that I have written the small combination of command statement to get the process ID/PID through name of process as below.

    $ps |grep XYZ|grep "ZEE"| grep JavaServer1 | awk '{ print $1 }'
    #17763

    $ps |grep XYZ|grep "ZEE"| grep JavaServer1 | awk '{ print $1 }'
    #17763

    where XYZ is user Name ; ZZZ is Environment name; JavaServer1 and JavaServer2 is processNames; output values are PID of that process.

    Using PIDs for capturing process statics for both as below.
    $prstat -p 17763,17724 >> Output.log

    PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
    17763 ZYX 345M 142M sleep 59 0 0:00:29 0.0% java/1
    17724 ZYX 630M 308M sleep 59 0 0:00:11 0.0% java/1

    Above both process ids are for JavaServer1 and JavaServer2 which are getting changed after restarting the Server after 4 Hrs and output of file getting blank.

    To Serarch the PID with Process name and collect in log, for that I have written below statements.

    $prstat -p `ps |grep XYZ|grep "ZEE"|grep -v grep| grep JavaServer1 awk '{ print $1 }'`
    PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
    17763 ZYX 345M 142M sleep 59 0 0:00:29 0.0% java/1

    above statements are working for single process name.
    but while updating another process name in the same statement then getting output for last statement included instade of both PIDs.
    $prstat -p `ps |grep XYZ|grep "ZEE"|grep -v grep| grep JavaServer1 awk '{ print $1 }';ps |grep XYZ|grep "ZEE"|grep -v grep| grep JavaServer2 awk '{ print $1 }'`
    PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
    17724 ZYX 630M 308M sleep 59 0 0:00:11 0.0% java/1

    Please help to get process details of both the process names still if server got restarted.

  • #2
    The canonical way to do this is to write *.pid files in /run (like /run/javaserver1.pid) that contain the PID of the process. Read it from there.

    Comment


    • #3
      you might also be better off using "pgrep" instead of "ps -efZ" or suchlike:

      pgrep -u XYZ -z ZEE JavaServer1

      however writing the PID to a logfile, as RealNC suggested, or at least logging to a file and using "fuser" on the file might suit you better.

      Comment

      Working...
      X