KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method that check if an external process is running.
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: April 3, 2015

Here is a utility method that check if an external process is running. It utilizes the command LAUNCH EXTERNAL PROCESS to execute the system command call to get the name of all running processes. It then checks if the name of the process is one of the names returned from the LAUNCH EXTERNAL PROCESS call.

// -------------------------------------------------------------------------------
// Name: IS_PROCESS_RUNNING
// Description: Method will check if the process is running. Check process by
// executing LAUNCH EXTERNAL PROCESS (Mac: "ps aux", PC: "tasklist")
// Parameters:
// $1 (Text) - Process name
//
// Output:
// $0 (Boolean) - Status of the process found (True - Found, False - Not Found)
// -------------------------------------------------------------------------------
C_BOOLEAN($0)
C_TEXT($1;$processName_t)
C_TEXT($cmd_t;$input_t;$output_t;$error_t)
C_LONGINT($pos_l)

If (Count parameters>=1)

   $processName_t:=$1

   If (Folder separator=":")
      $cmd_t:="ps aux"
   Else
      $cmd_t:="tasklist"
   End if

   LAUNCH EXTERNAL PROCESS($cmd_t;$input_t;$output_t;$error_t)

   $pos_l:=Position($processName_t;$output_t)
   If ($pos_l>0)
      $0:=True
   Else
      $0:=False
   End if

End if



Example of checking a process on PC:

C_BOOLEAN($status)

$status:=IS_PROCESS_RUNNING("4D.exe") // True - Found, False - Not Found


Example of checking a process on Mac

C_BOOLEAN($status)

$status:=IS_PROCESS_RUNNING("4D") // True - Found, False - Not Found