ProcessIOExample

Processes I/O

Source code:

   1 # SDA extension PROCIO is used by this program
   2 # make available the necessary modules
   3 import warnings
   4 warnings.filterwarnings(action='ignore',
   5                         message='tempnam is a potential security risk.*',
   6                         category=RuntimeWarning)
   7 import sys, posix, pprint, re, os
   8 from vms.starlet import getjpiw
   9 from vms.ssdef import SS__NOMOREPROC
  10 from vms.jpidef import JPI__PID, JPI__DIRIO, JPI__PRCNAM
  11 from vms.itemList import *
  12 from vms.crtl import to_vms
  13 # list which processes exist
  14 def show_processes():
  15     it = [itemList(code = JPI__PID, dtype = il_signedLong),
  16           itemList(code = JPI__PRCNAM, dtype = il_string),
  17           itemList(code = JPI__DIRIO, dtype = il_signedLong)]
  18     lst = []
  19     ctx = -1
  20     try:
  21         while(1):     # let loop terminate by exception
  22             s, ctx, dic = getjpiw(pid = ctx, itmlst = it)
  23             lst.append((dic[JPI__PRCNAM], dic[JPI__PID], dic[JPI__DIRIO]))
  24     except VMSError, e: # any exception aborts the loop
  25         if e.errno != SS__NOMOREPROC: raise
  26     return lst
  27 def procio(fncmd, fnlst, max_process):
  28     processes = show_processes()
  29     # sort the array
  30     processes.sort((lambda x,y: cmp(y[2], x[2])))
  31     f = open(fncmd, 'w')
  32     #   to avoid extension while writing fnlst
  33     print >> f, '$ set rms/ext=1000'
  34     print >> f, '$ ana/sys'
  35     print >> f, 'read sysdef'
  36     print >> f, 'set log', to_vms(fnlst)+'.'
  37     n = max_process
  38     for v in processes:
  39         print >> f, 'set proc/id= %X' % v[1]
  40         print >> f, 'procio p'
  41         n -= 1
  42         if n == 0: break
  43     f.close()
  44     s=os.popen('@'+to_vms(fncmd)+'.').read()
  45     f=open(fnlst, 'r')
  46     #   format the results
  47     fmt = "%-16s %8X %12d"
  48     head = "proc. name            pid    DIO count"
  49     print head
  50     for i in range(max_process):
  51         print fmt % (processes[i][0], processes[i][1], processes[i][2])
  52         line = f.readline()
  53         while line[:5] != '-----':
  54              line = f.readline()
  55         line = f.readline()
  56         while line and line[:5] != 'SDA> ':
  57             print line[:-1]
  58             line = f.readline()
  59     f.close()
  60 # if no parameter is given, the default of 4 processes will be displayed
  61 max_process = 4
  62 if len(sys.argv) > 1:
  63      max_process = int(sys.argv[1])
  64 # we create 2 temporary files in sys$scratch
  65 # because we should always be allowed to write in sys$scratch
  66 # command file
  67 fncmd = os.tempnam('/sys$scratch')
  68 # listing file
  69 fnlst  = os.tempnam('/sys$scratch')
  70 try:
  71     procio(fncmd, fnlst, max_process)
  72 except Exception, e:
  73     print e
  74 # delete the 2 temporary files
  75 os.unlink(fncmd)
  76 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
$
Recent