home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / pidsrv.zip / pidsrv.cmd < prev    next >
OS/2 REXX Batch file  |  1996-06-14  |  3KB  |  107 lines

  1. /*PID SERVER  v1.00*/
  2. /*Server side of program*/
  3.  
  4. RxExtraAPI = RxFuncQuery('RxExtra')  /* Checks for Rxextras */
  5. IF RxExtraAPI \= 0 THEN
  6.        DO
  7.                Call RxFuncAdd 'RxExtra', 'RxExtras' , 'RxExtra'
  8.                Call RxExtra 'Load'
  9.        END
  10.  
  11. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  12. Call SysLoadFuncs
  13.  
  14. Test = RxFuncQuery('GrxLoadFuncs')
  15. IF Test >< 0 THEN
  16.        Do
  17.        Call RxFuncAdd 'GrxLoadFuncs', 'GRXUTILS', 'GRXLOADFUNCS'
  18.        Call GrxLoadFuncs
  19.        END
  20. /************ Finished loading DLLs ******************/
  21.  
  22. Call SysCls
  23. Say 'PID Server v1.00'
  24. Say
  25. Say 'For best results run this program in a FULLSCREEN OS/2 session'
  26.  
  27. SIGNAL ON HALT
  28. pipename = '\PIPE\SFOGG\PIDSERVER'
  29. bufsize = 256
  30. queuename = '\QUEUES\SFOGG\PIDSERVER'
  31.  
  32. Say
  33. Say 'Starting Pipe'
  34.  
  35. Call GrxSrvrCreateNPipeThrd pipename, bufsize, queuename  /*Creating thread*/
  36.  
  37.    IF result >< 0 Then
  38.        Do
  39.            SAY 'Could not create server thread'
  40.            Say 'Try closing this OS/2 command line and starting a new one.'
  41.            EXIT
  42.        END
  43.  
  44. Say 'Server thread started successfully'
  45. Say 'Connecting to the thread.'
  46.  
  47. hpipe = GrxSrvrConnectNPipe()  /* Connecting to pipe */
  48.  
  49. Do while hpipe >< 0
  50.  
  51.        readrc = GrxReadNPipe(hpipe, 'readmsg')
  52.        IF readrc >< 0 THEN
  53.                DO
  54.                  Say 'Bad return code from function'
  55.                  Say 'Client probably disconnected....closing connection.'
  56.                  disconnectrc = GrxSrvrDisconnectNPipe(hpipe)
  57.                  Say 'Restarting Connection'
  58.                  hpipe = GrxSrvrConnectNPipe()
  59.                End
  60.  
  61.        Call received(readmsg)
  62.  
  63.  
  64. End
  65.  
  66. Exit
  67.  
  68. RECEIVED:
  69. ARG input
  70.  
  71. IF input = 'L' THEN                    /*Client asked for a process list*/
  72.        DO
  73.          Call RxQuerySwitchList 'temp.'
  74.              DO COUNT = 2 to temp.0
  75.                 msg = temp.count temp.count.PID '*****'
  76.                 writerc = GrxWriteNPipe(hpipe, msg)
  77.              END
  78.  
  79.        END
  80.  
  81. Else IF datatype(input, N) THEN      /*Received number...process to kill*/
  82.        DO
  83.           rc = RxKillProcess(input)
  84.           msg = 'Process status is:' rc
  85.           writerc = GrxWriteNPipe(hpipe, msg)
  86.  
  87.        END
  88. ELSE                         /*Bad data from pipe*/
  89.        DO
  90.           msg = 'Error...no action taken'
  91.           writerc = GrxWriteNPipe(hpipe, msg)
  92.        END
  93.  
  94.  
  95. msg = "Enter 'L' to see list of running programs or PID# to kill another."
  96. writerc = GrxWriteNPipe(hpipe, msg)
  97. msg = '0000'                        /*Keeps client from trying to read empty pipe*/
  98. writerc = GrxWriteNPipe(hpipe, msg)
  99.  
  100. RETURN
  101.  
  102. HALT:
  103.        SAY 'BREAK PRESSED, EXITING..........'
  104.        BEEP(250,250)
  105.        EXIT
  106.  
  107.