extProgramStatus (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

All

Firmware version:

1.00.00


This function checks the status of an external program and to release the handle once the program exits.

 

Input:

handle : SYSHANDLE

A handle to the program to check the status of.

 

Output:

handle : SYSHANDLE

If the program is stopped, the handle is released and made invalid.

 

code : DINT

The status code of an exited program or the signal that caused the status of the program to change.

 

Returns: INT

3

- The program is stopped. Code contains the signal that made it stop.

2

- The program is terminated because of a signal. Code contains the signal that made it terminate. Handle has been made invalid.

1

- The program has exited normally. Code contains the status code from the program. Handle has been made invalid.

0

- The program is still running.

-1

- Handle is not valid.

-2

- Error checking the status. A likely cause is that the process has ended and the status has already been checked.

 

Declaration:

FUNCTION extProgramStatus : INT;
VAR_INPUT
  handle : ACCESS SYSHANDLE;
  code : ACCESS DINT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc     : INT;
  signal : DINT;
  handle : SYSHANDLE;
END_VAR;
 
BEGIN
  ...
  fsMediaOpen(media := 1);
  // Start the program SERVER.RPX with four arguments: "-port" "3490" "-name" and "test server".
  rc := extProgramStart(handle := handle, path := "B:\SYSTEM\EXT\SERVER.RPX",
     args := "-port 3490 -name $"test server$"");
  DebugFmt(message := "Server started: \1", v1 := rc);
  ...
  // Stop the program by sending the Terminate signal
  rc := extProgramSignal(handle := handle, signal := 9);
  DebugFmt(message := "Send kill: \1", v1 := rc);
  // Request status
  rc := extProgramStatus(handle := handle, code := signal);
  IF rc = 2 THEN
    DebugFmt(message := "Program was terminated with the \4 signal", v4 := signal);
  END_IF;
END;
END_PROGRAM;