File Handles When Spawning from a MOVE Application

ID: Q90800


The information in this article applies to:


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 query words: kbinf 1.00 1.50 5.30 5.31.009 5.60 spawn exec


Keywords          : kb16bitonly 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: July 27, 1999