home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxusmp.zip / pi2.cmd < prev    next >
OS/2 REXX Batch file  |  1994-01-10  |  6KB  |  239 lines

  1. /* rexx */
  2.  
  3. tab = '09'x
  4.  
  5. signal on halt
  6.  
  7. if rxfuncquery('rxqprocstatus') then
  8.   do
  9.   call rxfuncadd 'yinit','ydbautil','rxydbautilinit'
  10.   call yinit
  11.   end
  12.  
  13. arg opts
  14.  
  15. if opts = '?' | opts = 'HELP' then
  16.   do
  17.   say;say 'Syntax:'
  18.   say tab 'PI2  /switch=val';say
  19.   say 'where:';say
  20.   say tab 'switch -' tab 'P  = Prefix of executable file name'
  21.   say tab tab tab        'N  = process number (hex/decimal)'
  22.   say tab tab tab        'PN = parent process number (hex/decimal)'
  23.   say tab tab tab        'F  = function:'
  24.   say tab tab tab tab          'LIST'
  25.   say tab tab tab tab          'CHILDREN'
  26.   say tab tab tab tab          'DEPENDENTS'
  27.   say tab tab tab tab          'PARENTS'
  28.   say tab tab tab tab          'ANCESTORS'
  29.   say;say 'Examples:';say
  30.   say tab 'To list all processes whose executable file name begins with'
  31.   say tab 'the characters PM, you would type:';say
  32.   say tab tab 'pi2 /p=pm';say
  33.   say tab 'To list the process whose process-id is decimal 13, you would type:'
  34.   say tab tab 'pi2 /n=13';say
  35.   say tab 'To list the process whose process-id is hex 1c, you would type:'
  36.   say tab tab 'pi2 /n=x1c';say
  37.   exit
  38.   end
  39.  
  40. srchpn = ''
  41. srchppn = ''
  42. pref = ''
  43. fargs = ''
  44. func = ''
  45. do i=1 to words(opts)
  46.   opt = word(opts,i)
  47.   select
  48.     when wordpos(left(opt,1),'/ -') > 0 then
  49.       do
  50.       parse var opt . 2 optcd '=' optval
  51.       select
  52.         when optcd = 'P' then
  53.           pref = optval
  54.         when optcd = 'F' then
  55.           do
  56.           select
  57.             when abbrev('LIST',optval) then
  58.               func = 'LIST'
  59.             when abbrev('CHILDREN',optval) then
  60.               do
  61.               func = 'CHILDREN'
  62.               fargs = fargs || 'l'
  63.               end
  64.             when abbrev('DEPENDENTS',optval) then
  65.               do
  66.               func = 'DEPENDENTS'
  67.               fargs = fargs || 'l'
  68.               end
  69.             when abbrev('PARENTS',optval) then
  70.               do
  71.               func = 'PARENTS'
  72.               end
  73.             when abbrev('ANCESTORS',optval) then
  74.               do
  75.               func = 'ANCESTORS'
  76.               end
  77.             otherwise
  78.               do
  79.               say '"'opt'" specifies an invalid function.'
  80.               exit
  81.               end
  82.           end
  83.           end
  84.         when optcd = 'N' | optcd = 'PN' then
  85.           do
  86.           if left(optval,1) = 'X' then
  87.             do
  88.             pn = substr(optval,2)
  89.             if \datatype(pn,'x') then
  90.               do
  91.               say '"'opt'" specifies an invalid hexadecimal process number.'
  92.               exit
  93.               end
  94.             if optcd = 'N' then
  95.               srchpn = x2d(pn)
  96.             else
  97.               srchppn = x2d(pn)
  98.             end
  99.           else
  100.             do
  101.             if \datatype(optval,'w') then
  102.               do
  103.               say '"'opt'" specifies an invalid decimal process number.'
  104.               exit
  105.               end
  106.             if optcd = 'N' then
  107.               srchpn = optval
  108.             else
  109.               srchppn = optval
  110.             end
  111.           end
  112.         otherwise
  113.           do
  114.           say '"'opt'" is an invalid option.'
  115.           exit
  116.           end
  117.       end
  118.       end
  119.     otherwise
  120.       do
  121.       if pref = '' then
  122.         pref = opt
  123.       end
  124.   end
  125. end
  126.  
  127. if func = 'DEPENDENTS' then
  128.   do
  129.   call rxqprocstatus 'q.',fargs
  130.   do i=1 to q.0l.0
  131.     idx = q.0l.i
  132.     exename = translate(filespec('n',q.0l.idx.1))
  133.     if (left(exename,length(pref)) = pref) then
  134.       do
  135.       lvl = 1
  136.       found = ''
  137.       call libname q.0l.i
  138.       return
  139.       end
  140.   end
  141.   return
  142.   end
  143.  
  144. if func = '' then
  145.   func = 'LIST'
  146.  
  147. if wordpos(func,'LIST CHILDREN') > 0 then
  148.   do
  149.   call rxqprocstatus 'q.',fargs
  150.   do i=1 to q.0p.0
  151.     ok = 1
  152.     exename = translate(filespec('n',q.0p.i.6))
  153.     if length(srchppn) > 0 then
  154.       ok = ok & (x2d(q.0p.i.2) = srchppn)
  155.     else
  156.       ok = ok & 1
  157.     if length(srchpn) > 0 then
  158.       ok = ok & (x2d(q.0p.i.1) = srchpn)
  159.     else
  160.       ok = ok & 1
  161.     if (left(exename,length(pref)) = pref) & ok then
  162.       do
  163.       say;say q.0p.i.6
  164.       msg='pid='q.0p.i.1',ppid='q.0p.i.2',sgid='q.0p.i.5',status='
  165.       if pos('?',q.0p.i.4) > 0 then
  166.         msg = msg || q.0p.i.4
  167.       else
  168.         msg = msg || subword(q.0p.i.4,2)
  169.       say msg
  170.       do t=1 to q.0p.i.0t.0
  171.         msg='tid='q.0p.i.0t.t.1',slot='q.0p.i.0t.t.2',slpid='q.0p.i.0t.t.3||,
  172.             ',prty='right(q.0p.i.0t.t.4,4)',stime/utime='q.0p.i.0t.t.5'/'q.0p.i.0t.t.6',state='
  173.         if pos('?',q.0p.i.0t.t.7) > 0 then
  174.           msg = msg || q.0p.i.0t.t.7
  175.         else
  176.           msg = msg || subword(q.0p.i.0t.t.7,2)
  177.         say msg
  178.       end
  179.       if func = 'CHILDREN' then
  180.         do l=1 to q.0p.i.0l.0
  181.           lvl = 1
  182.           found = ''
  183.           call libname q.0p.i.0l.l
  184.         end
  185.       end
  186.   end
  187.   return
  188.   end
  189.  
  190. if func = 'ANCESTORS' then
  191.   do
  192.   call rxqprocstatus 'q.','l'
  193.   do i=1 to q.0l.0
  194.     idx = q.0l.i
  195.     modname = translate(filespec('n',q.0l.idx.1))
  196.     if modname = pref then
  197.       do
  198.       modidx = q.0l.i
  199.       leave
  200.       end
  201.   end
  202.   say 'Processes using the module' pref
  203.   do i=1 to q.0p.0
  204.     do l=1 to q.0p.i.0l.0
  205.       if q.0p.i.0l.l = modidx then
  206.         do
  207.         say '  'q.0p.i.6
  208.         leave l
  209.         end
  210.     end
  211.   end
  212.   return
  213.   end
  214.  
  215. exit
  216.  
  217. libname: procedure expose q. lvl found
  218. lvl = lvl + 1
  219. do x=1 to q.0l.0
  220.   if arg(1) = q.0l.x then
  221.     do
  222.     found = found q.0l.x
  223.     idx = q.0l.x
  224.     say copies(' ',2*lvl) || q.0l.idx.1
  225.     do i=1 to q.0l.idx.0i.0
  226.       if wordpos(q.0l.idx.0i.i,found) = 0 then
  227.         call libname q.0l.idx.0i.i
  228.     end
  229.     lvl = lvl - 1
  230.     return
  231.     end
  232. end
  233. lvl = lvl - 1
  234. return '?'
  235.  
  236. halt:
  237. drop q.
  238. exit
  239.