File Handles When Spawning from a MOVE Application

Last reviewed: July 17, 1997
Article ID: Q90800
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg kbfasttip

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE) included with:

        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C/C++ for Windows, versions 1.0 and 1.5
    

SUMMARY

A program using the MOVE overlay manager that spawns a child program will not behave the same as a program that does not use the MOVE overlay manager. The memory allocated to the XMS and EMS overlay caches is not released before the spawn. This must be done explicitly with the _movepause() function.

The documentation for _movepause() is in the file MOVEAPI.TXT included with C/C++ and is in MOVEAPI.WRI in Visual C++. It states the following about the function:

   The _movepause function frees the cache memory and closes the
   executable file.

This is useful when the program that is spawned uses extended or expanded memory. If spawning with P_WAIT or preparing for an abnormal termination, calling _movepause() is the only way to make sure that the cache is released.

Normally, files that are open when a spawn occurs will remain open in the child process. The MOVE overlay manager keeps a file handle to the executable open until termination. Calling _movepause() will close this file handle that would otherwise remain open after a spawn or after an abnormal termination.

MORE INFORMATION

The following sample demonstrates the result of using _movepause() to release the file handle to a MOVE application. There are two programs that spawn each other with P_OVERLAY. As is, the 16th spawn will fail with the message:

   Spawn failed: Too many open files

If the calls to _movepause() are uncommented, they will spawn each other infinitely. To break the loop, press CTRL+C.

Sample Code

MAIN1.C

/*
 * Compiler options needed: /AM /c
 * LINK command: main1 over1,,,,main1.def
 */

#include <stdio.h>
#include <process.h>

/* You may need to change the path in the following include statement
   if MOVEAPI.H is not in the "c:\c700\source\move" directory */
// Remove the comment from the following line to free handle
// #include "c:\c700\source\move\moveapi.h"

void func1(void);

void main()
{
   int count;

   func1();

//   _movepause();                  // Remove comment to free handle

   if (_spawnl(P_OVERLAY, "main2.exe", NULL) == -1)
      perror("Spawn failed");
}

OVER1.C

#include <stdio.h>

void func1()
{
   printf("In func1.\n");
}

MAIN1.DEF

SEGMENTS

   over1_text OVL:1

MAIN2.C

/*
 * Compiler options needed: /AM /c
 * LINK command: main2 over2,,,,main2.def
 */

#include <stdio.h>
#include <process.h>

/* You may need to change the path in the following include statement
   if MOVEAPI.H is not in the "c:\c700\source\move" subdirectory */
// Remove the comment from the following line to free handle
// #include "c:\c700\source\move\moveapi.h"

void func2(void);

void main()
{
   int count;
   func2();

//   _movepause();                      // Uncomment to free handle

   if (_spawnl(P_OVERLAY, "main1.exe", NULL) == -1)
      perror("Spawn failed");
}

OVER2.C

#include <stdio.h>

void func2()
{
   printf("In func2.\n");
}

MAIN2.DEF

SEGMENTS

   over2_text OVL:1


Additional reference words: kbinf 1.00 1.50 5.30 5.31.009 5.60 spawn exec
KBCategory: kbprg kbfasttip
KBSubcategory: MoveOverlay
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.