NCL Home > Documentation > Functions > System tools

subprocess_wait

Checks the finish-status of a concurrent process launched by the subprocess command. Can optionally wait for the subprocess to finish.

Available in version 6.5.0 and later.

Prototype

	function subprocess_wait (
		id       [1] : integer,  
		is_blocking  : logical   
	)

	return_val [1] :  integer

Arguments

id

The ID of a subprocess to wait for. A negative value indicates to wait for any subprocess. Otherwise, should be a value that was returned by a call to subprocess.

is_blocking

A logical determining whether subprocess_wait waits or returns immediately if the process ID has not yet finished.

Return value

Returns the ID of the subprocess that has finished, or -1 if no subprocesses have finished.

Description

This function is used in conjunction with subprocess to coordinate and synchronize with concurrent subprocesses. It is used to determine whether or when subprocesses have finished. There are two modes of operation: wait vs. status-check. If is_blocking is "True", then this function waits for the given process id to finish executing, or waits for any process to finish if id is negative. The function returns immediately if is_blocking is "False", returning the id of the/a finished process or -1 if no process has finished since the last call.

See Also

subprocess system systemfunc

Examples

Example 1

Simple example to run a concurrent subtask, continue executing NCL script, and subsequently wait for the subtask to finish:

begin
   pid = subprocess("computePiToABillionDecimals")

   ; NCL continues executing...
   ...

   pid = subprocess(pid, True)  ; 
   print("Process " + pid + " has finished")
end
Example 2

Launches several subtasks, and waits for them to finish in any order:

begin
  numTimeSteps = 5
  do i=0,numTimeSteps
    ; note we don't keep track of the IDs
    pid = subprocess("ncl subtask.ncl 'timestep=" + i + "'")
  end do

  ; NCL continues executing...
  ...

  numFinished = 0
  do while(numFinished.lt.numTimeSteps) 
    pid = subprocess(-1, True)
    numFinished = numFinished + 1
  end do
end