Returning the state of a child process

exitcode()

Returning the state of a child process


SYNTAX

exitcode (server_name, child_handle, wait_msecs)

Returns the current state of a child process running concurrently. The child process is executed by means of the execute() function.

The function returns one of the following values. The CHILD_PROCESS_ values are defined in <sculptor.h>.

CHILD_PROCESS_RUNNING

The process is still running.

CHILD_PROCESS_INTERRUPTED

The process was terminated by an interrupt.

CHILD_PROCESS_FAILED

Execution of the task (by the execute() function) was not successful.

0-255

The process terminated with this exit code.

>255

If the process exit code is greater than 255, only the low order byte is returned. This is a system limitation on both UNIX and Windows.


server_name

The name of the server on which the task was run. This value should be set to NULL or to a null string if the task was a local process.

child_handle

A field containing the handle. The handle is the return value from the execute() function call that started the child process, and should be stored in an i4 type field.

wait_msecs

The number of milliseconds to wait. If this is zero, the function returns the current state of the child process immediately. Otherwise it waits until the process terminates or until the specified number of milliseconds has elapsed, whichever occurs first.

It is bad practice to use a wait time longer than a few seconds because this prevents Sculptor from processing messages. Windows programs should process messages at frequent intervals to prevent undesirable effects such as not painting a revealed window. However, a pure code loop wastes CPU time that can be better allocated to other tasks. The best practice is to use a delay loop as in the example below.


NOTES

  • When Windows Task manager is used to end a process, it appears to exit with 1 (if “End Task” is used) or 0 (if “End Process” is used). This has only been determined by experiment and has not been found in any documentation.

  • The exit status of a process executed by the exec command is returned in sys.Status.


EXAMPLE

!temp ExitCode,,i4
!temp Handle1,,i4

    tmp.Handle1 = execute(NULL, "-scc " + Quote(SourcePath), NULL, 0, AA_SHOWNORMAL)

    do {
          tmp.ExitCode = exitcode(NULL, tmp.Handle1, 500)
    } while (tmp.ExitCode == CHILD_PROCESS_RUNNING)

RELATED TOPICS

close_handle()

end_process()

execute()

exec