home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / TOOLS / DIALIP / KILLBN.CMD < prev    next >
OS/2 REXX Batch file  |  1996-12-19  |  2KB  |  56 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. /*say 'entered with optoins ='options'='    'searchname ='searchname'='*/
  12. tmp = value( 'TMP', , 'OS2ENVIRONMENT' )
  13. listfile = SysTempFileName( tmp'\kilbntmp.???' )
  14. 'pstat /c > 'listfile
  15.  
  16. just_find_flag = 'N'
  17. return_hex_flag = 'N'
  18. decpid = -1
  19. pid = -1
  20. if ( left( options, 1 ) \= '-' ) then
  21.     Do
  22.     num_to_kill = searchname
  23.     searchname = options
  24.     End
  25. else if ( pos( '-FX', options ) > 0 ) then
  26.     Do
  27.     just_find_flag = 'Y'
  28.     return_hex_flag = 'Y'
  29.     End
  30. else if ( pos( '-F', options ) > 0 ) then
  31.     just_find_flag = 'Y'
  32.  
  33. Do While( lines( listfile ) )
  34.     word = linein( listfile )
  35.     parse var word pid . . procname rest
  36.     say "pid ="pid     "procname ="procname"="
  37.     if ( pos( searchname, procname ) > 0 ) then
  38.         Do
  39.         decpid = x2d( pid )
  40.         if ( just_find_flag = 'Y' ) then
  41.             Do
  42.             say 'found name with hex pid = 'pid   'decpid = 'decpid
  43.             leave
  44.             End
  45.         "kill "decpid
  46.         leave
  47.         End
  48. End
  49. rc = stream( listfile, 'c', "close" )
  50. "del "listfile
  51. if return_hex_flag = 'Y' then
  52.     return pid
  53. else
  54.     return decpid
  55.  
  56.