Microsoft KB Archive/90800

{|
 * width="100%"|

File Handles When Spawning from a MOVE Application

 * }

Q90800

-

The information in this article applies to:


 * The C/C++ Compiler (CL.EXE), included with:
 * Microsoft C/C++ for MS-DOS, version 7.0
 * Microsoft Visual C++, versions 1.0, 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.

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


 * 1) include 
 * 2) include 

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

void func1(void);

void main {  int count;

func1;

//  _movepause;                  // Remove comment to free handle

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

OVER1.C
#include 

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

MAIN1.DEF
SEGMENTS over1_text OVL:1

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


 * 1) include 
 * 2) include 

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

void func2(void);

void main {  int count; func2;

//  _movepause;                      // Uncomment to free handle

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

OVER2.C
#include 

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

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

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCVCComp