User Tools

Site Tools


processioexample

Processes I/O

Source code:

#!python
# SDA extension PROCIO is used by this program
# make available the necessary modules
import warnings
warnings.filterwarnings(action='ignore',
                        message='tempnam is a potential security risk.*',
                        category=RuntimeWarning)
import sys, posix, pprint, re, os
from vms.starlet import getjpiw
from vms.ssdef import SS__NOMOREPROC
from vms.jpidef import JPI__PID, JPI__DIRIO, JPI__PRCNAM
from vms.itemList import *
from vms.crtl import to_vms
# list which processes exist
def show_processes():
    it = [itemList(code = JPI__PID, dtype = il_signedLong),
          itemList(code = JPI__PRCNAM, dtype = il_string),
          itemList(code = JPI__DIRIO, dtype = il_signedLong)]
    lst = []
    ctx = -1
    try:
        while(1):     # let loop terminate by exception
            s, ctx, dic = getjpiw(pid = ctx, itmlst = it)
            lst.append((dic[JPI__PRCNAM], dic[JPI__PID], dic[JPI__DIRIO]))
    except VMSError, e: # any exception aborts the loop
        if e.errno != SS__NOMOREPROC: raise
    return lst
def procio(fncmd, fnlst, max_process):
    processes = show_processes()
    # sort the array
    processes.sort((lambda x,y: cmp(y[2], x[2])))
    f = open(fncmd, 'w')
    #   to avoid extension while writing fnlst
    print >> f, '$ set rms/ext=1000'
    print >> f, '$ ana/sys'
    print >> f, 'read sysdef'
    print >> f, 'set log', to_vms(fnlst)+'.'
    n = max_process
    for v in processes:
        print >> f, 'set proc/id= %X' % v[1]
        print >> f, 'procio p'
        n -= 1
        if n == 0: break
    f.close()
    s=os.popen('@'+to_vms(fncmd)+'.').read()
    f=open(fnlst, 'r')
    #   format the results
    fmt = "%-16s %8X %12d"
    head = "proc. name            pid    DIO count"
    print head
    for i in range(max_process):
        print fmt % (processes[i][0], processes[i][1], processes[i][2])
        line = f.readline()
        while line[:5] != '-----':
             line = f.readline()
        line = f.readline()
        while line and line[:5] != 'SDA> ':
            print line[:-1]
            line = f.readline()
    f.close()
# if no parameter is given, the default of 4 processes will be displayed
max_process = 4
if len(sys.argv) > 1:
     max_process = int(sys.argv[1])
# we create 2 temporary files in sys$scratch
# because we should always be allowed to write in sys$scratch
# command file
fncmd = os.tempnam('/sys$scratch')
# listing file
fnlst  = os.tempnam('/sys$scratch')
try:
    procio(fncmd, fnlst, max_process)
except Exception, e:
    print e
# delete the 2 temporary files
os.unlink(fncmd)
os.unlink(fnlst)

Result:

$ python procio.py
proc. name            pid    DIO count
BATCH_213        20200154      3999955
          1     15769  DISK$DATA2:[users1.ASSP_USER]maillog.txt;1
          0      6131  DISK$DATA2:[users1.ASSP_USER]LOGIN_ASSP.LOG;36
          1         0  DISK$AXPVMSSYS:[SYSCOMMON.SYSMGR]LOGIN_ASSP.COM;17
          0         0  DISK$AXPVMSSYS:[SYSCOMMON.SYSMGR]LOGIN_ASSP.COM;17
MYSQL_SERVER     20200156       168803
       3845      2876  DISK$DATA2:[TOOLS.MYSQL.DATA]ibdata1.;1
        567       327  DISK$DATA2:[TOOLS.MYSQL.DATA]ib_logfile0.;1
          1        16  DISK$DATA2:[TOOLS.MYSQL.DATA]bisou-bin.000032;1
          0         4  DISK$DATA2:[TOOLS.MYSQL.MYSQL_SERVER]MYSQLD.LOG;34
          2         2  DISK$DATA2:[TOOLS.MYSQL.DATA]bisou-bin.index;1
          1         0  DISK$DATA2:[TOOLS.MYSQL.VMS.MYSQL]run_mysqld.com;1
          1         0  DISK$DATA2:[TOOLS.MYSQL.MYSQL_SERVER.TMP]ibeaa200156.;1
          1         0  DISK$DATA2:[TOOLS.MYSQL.DATA]ib_logfile1.;1
          1         0  DISK$DATA2:[TOOLS.MYSQL.MYSQL_SERVER.TMP]ibfaa200156.;1
          0         0  DISK$DATA2:[TOOLS.MYSQL.MYSQL_SERVER.TMP]ibdaa200156.;1
HTTPd:80         2020015B       151061
          3      6225  DISK$DATA1:[HTTP.HT_ROOT.LOG]WWW-PI-NET-DYNDNS-OR_80_20041001_ACCESS.LOG;1
       2071         0  DISK$AXPVMSSYS:[SYSCOMMON.SYSEXE]RIGHTSLIST.DAT;1
          2      1928  DISK$DATA1:[HTTP.HT_ROOT.LOG]VMSPYTHON-DYNDNS-ORG_80_20041001_ACCESS.LOG;1
          2       391  DISK$DATA1:[HTTP.HT_ROOT.LOG]VMSMYSQL-DYNDNS-ORG_80_20041001_ACCESS.LOG;1
          2       387  DISK$DATA1:[HTTP.HT_ROOT.LOG]WWW-PI-NET-DYNDNS-O_443_20041001_ACCESS.LOG;1
          2       385  DISK$DATA1:[HTTP.HT_ROOT.LOG]WWW-PI-NET-DYNDNS-_4443_20041001_ACCESS.LOG;1
          0        92  DISK$DATA1:[HTTP.HT_ROOT.LOG_SERVER]BISOU_20041010161953.LOG;1
         30         0  DISK$AXPVMSSYS:[SYSCOMMON.SYSEXE]SYSUAF.DAT;1
         28         0  DISK$AXPVMSSYS:[SYSCOMMON.SYSEXE]SYSUAF.DAT;1
          4         0  DISK$AXPVMSSYS:[SYSCOMMON.SYSEXE]SYSUAF.DAT;1
          1         0  DISK$DATA1:[HTTP.HT_ROOT.STARTUP]STARTUP_SERVER.COM;3
QUEUE_MANAGER    20200111       129988
      82854         0  DISK$AXPVMSSYS:[SYSCOMMON.SYSEXE]RIGHTSLIST.DAT;1
       1301         0  DISK$AXPVMSSYS:[SYSCOMMON.SYSEXE]SYSUAF.DAT;1
          0        55  DISK$AXPVMSSYS:[SYSCOMMON.SYSEXE]SYS$QUEUE_MANAGER.QMAN$JOURNAL;1
          3        17  DISK$AXPVMSSYS:[SYSCOMMON.SYSEXE]SYS$QUEUE_MANAGER.QMAN$QUEUES;1
          8         2  DISK$AXPVMSSYS:[SYSCOMMON.SYSEXE]QMAN$MASTER.DAT;1
$
processioexample.txt · Last modified: 2014/09/16 15:34 by wikiadmin