Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ exit(DOS) — OpenDesktop Software Development System 1.0.0d

Media Vault

Software Library

Restoration Projects

Artifacts Sought

     Name
          exit, _exit - Terminate the calling process.

     Syntax
          #include <process.h>
          #include <stdlib.h>

          void exit(status)
          void _exit(status)
          int status;

     Description
          The exit and _exit functions terminate the calling process.
          The exit function first calls the functions registered by
          atexit, then flushes all buffers and closes all open files
          before terminating the process. The _exit function
          terminates the process without processing atexit functions
          or flushing stream buffers.  The status value is typically
          set to 0 to indicate a normal exit and set to some other
          value to indicate an error.

          Although the exit and _exit calls do not return a value, the
          low-order byte of status is made available to the waiting
          parent process, if there is one, after the calling process
          exits. The status value is available to the operating system
          batch command IF ERRORLEVEL.

     Return Value
          None.

     See Also
          abort(DOS), atexit(DOS), exec(DOS), spawn(DOS), system(DOS)

     Example
          #include <stdio.h>

          main( )
           {
                  FILE *stream;
                  char aChar;

                  stream = fopen("data", "w+");
                  printf("About to exit...\nFlush buffers ");
                  printf("for the file 'data'? (y/n): ");

                  aChar = getch();
                  aChar = toupper(aChar);
                  fprintf(stream, "This will appear in 'data' ");
                  fprintf(stream, "only if buffers are flushed.\n");

                  if (aChar == 'Y') {
                           printf("\nExiting and flushing buffers\n");
                           exit(0);
                  }
                  else {
                          printf("\nExiting, but buffers ");
                          printf("are not flushed.\n");
                          _exit(0);
                  }
           }

          This program opens the file named data and prompts the user
          to choose how to close the file. Based on the user's choice,
          the program closes the file using the exit function, which
          flushes buffers, or the _exit function, which does not.

                                                (printed 6/18/89)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026