home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / dialip2.zip / killbn.cmd < prev    next >
OS/2 REXX Batch file  |  1999-01-31  |  2KB  |  79 lines

  1. /* program: killbyname  (a freeby)
  2. ** written: Stan J. Towianski
  3. ** purpose: killbyname arg, will kill the 1st process that matches the
  4. **          name given in arg.
  5. **    date: 1995
  6. **    note: needs to have kill.exe program in path.
  7. **          This can be found in c:\grpware\clients from OS/2 Warp 3.0
  8. */
  9.  
  10. parse upper arg options searchname num_to_kill
  11.  
  12. /*say 'entered with options ='options'='    'searchname ='searchname'='*/
  13. dosrc = rxqprocstatus('q.','')
  14.  
  15. just_find_flag = 'N'
  16. return_hex_flag = 'N'
  17. decpid = -1
  18. pid = -1
  19. if ( left( options, 1 ) \= '-' ) then
  20.     Do
  21.     num_to_kill = searchname
  22.     searchname = options
  23.     End
  24. else if ( pos( '-FX', options ) > 0 ) then
  25.     Do
  26.     just_find_flag = 'Y'
  27.     return_hex_flag = 'Y'
  28.     End
  29. else if ( pos( '-F', options ) > 0 ) then
  30.     just_find_flag = 'Y'
  31.  
  32. n = 1
  33. parse var searchname searchname.n ',' searchname
  34. say 'will kill session ='searchname.n'='
  35. do while( searchname \= '' )
  36.     n = n + 1
  37.     parse var searchname searchname.n ',' searchname
  38.     say 'will kill session ='searchname.n'='
  39. End
  40. searchname.0 = n
  41. left_to_kill = n
  42.  
  43. Say 'There are' q.0p.0 'processes ('q.0g.1 'threads) running right now'
  44. do n=1 to q.0p.0  /* number of processes */
  45. /*    say;say '==== Process ('q.0p.n.1')'q.0p.n.6' ===='*/
  46.     pid = q.0p.n.1
  47.     procname = q.0p.n.6
  48. /*    say "pid ="pid     "procname ="procname"="*/
  49.     do_kill = NO
  50.     do c = 1 to searchname.0
  51.         if ( pos( searchname.c, procname ) > 0 ) then
  52.             Do
  53.             do_kill = YES
  54.             leave
  55.             End
  56.     End
  57.     if ( do_kill = YES ) then
  58.         Do
  59.         decpid = x2d( pid )
  60.         if ( just_find_flag = 'Y' ) then
  61.             Do
  62. /*            say 'found name with hex pid = 'pid   'decpid = 'decpid*/
  63.             leave
  64.             End
  65.         "kill "decpid
  66.         left_to_kill = left_to_kill - 1
  67.         if ( left_to_kill < 1 ) then
  68.             Do
  69.             say 'killed all sessions'
  70.             leave
  71.             End
  72.         End
  73. End
  74. if return_hex_flag = 'Y' then
  75.     return pid
  76. else
  77.     return decpid
  78.  
  79.