exit: Exit an ECB

This function ends a program.

Last updated

Changed in 2024 (information only; no code change).

Format

#include   <stdlib.h>            
void       exit(int return_code);
return_code
Integer value indicating status.
Using the exit function is one way to cause normal program termination. (The other ways are calling the basic assembler language (BAL) EXITC macro and returning from the initial main function.) During normal program termination:
  1. All functions registered by the atexit function are called in last-in-first-out (LIFO) order. In the C++ language, the destructors of objects with static storage duration are also called concurrently during this step. For additional guarantees about calling order, see the C++ documentation for the exit function.
  2. All open file streams and all open file descriptors are closed.
    Note: Sockets are not closed and must be closed explicitly by the application.
  3. All files that are created by the tmpfile function are deleted.
  4. Control returns to the host environment.
  5. If the entry control block (ECB) was created by a call to the system function, the tpf_cresc function, or the BAL CRESC macro, the return_code value returns to the parent program, which resumes running after the child ECB has exited. Otherwise, the z/TPF system ignores the return_code value.

Stack is not unwound. In the C++ language, destructors of variables with automatic storage duration are not called.

Normal return

The exit function does not return to its caller. This function gives control to the z/TPF system, which exits the ECB. If the ECB was created by a parent ECB through the system or tpf_cresc functions, or the BAL CRESC macro, the z/TPF system reactivates the parent ECB. For example, if program A calls program B through a call to the system function, and program B calls the exit function, program B exits and program A resumes running at the next sequential instruction (NSI).

Error return

Not applicable.

Programming considerations

  • Following the call to the exit function, no return is made to the operational program.
  • If the exit function is called in a commit scope, control is transferred to the system error routine and processing ends as if a rollback was issued. The DASD surface remains unchanged.
  • The return code parameter is used only if the exiting program was created by using an ECB create macro such as tpf_cresc. In this case, the parent ECB is currently waiting for an event to be completed. When all child ECBs that were created by this parent ECB have exited, the event has completed successfully and control returns to the parent ECB.

Examples

The following example exits the ECB when processing is completed. No system error is issued.
#include <stdlib.h>
int main(void)
⋮
exit(0);