PRB: After Increasing Available File Handles, exec() Hangs

ID Number: Q58779

5.00 5.10 6.00 6.00a 6.00ax

MS-DOS

buglist5.10 buglist6.00 buglist6.00a buglist6.00ax buglist7.00

Summary:

SYMPTOMS

In Microsoft C versions 5.1, 6.0, 6.0a, 6.0ax, and C/C++ version 7.0,

if you have increased the maximum number of file handles and buffers

available to the system by changing the _file.c and crt0dat.asm

startup source files as outlined in the README.DOC file, and then

write a program that does multiple execs, your machine may halt under

MS-DOS.

CAUSE

There is a known incompatibility between changing the startup

source code for the optimizing C compilers and exec'ing multiple

child processes.

STATUS

Microsoft has confirmed this to be a problem in C versions 5.0,

5.1, 6.0, 6.0a, 6.0ax, and C/C++ version 7.0. We are researching this

problem and will post new information here as it becomes available.

More Information:

The sample code below demonstrates this problem. If you make a copy of

this program and call it CHILD.C, and change all references in the

CHILD.C program from child to parent, you will have a loop of exec's

set up. You can exec the child once, then your machine either hangs on

the call to exec() the first program again or as the second program is

finishing execution.

Sample Code

-----------

#define FILES_OPEN 30

#include <stdio.h>

#include <conio.h>

#include <process.h>

#include <errno.h>

#include <string.h>

void main ( void )

{

short numfiles, returnval;

FILE *FilePointer;

char fname[80];

for ( numfiles = 0; numfiles < FILES_OPEN; numfiles ++ )

{

sprintf ( fname, "file%2d.dat", numfiles ) ;

printf ( "Opening file #%2d :%s\n", numfiles, fname ) ;

if ( ( FilePointer = fopen ( fname, "a+" ) ) == NULL )

{

printf ( "fopen failed on file #%2d", numfiles ) ;

exit ( -2 ) ;

}

}

printf ( " Press <esc> to quit, other to continue exec'ing child: \n" ) ;

if ( ( returnval = getche() ) == 27 )

{

printf ( "Quitting...\n" ) ;

exit ( 1 ) ;

}

if ( ( returnval = execlp ( "child.exe", "child.exe", NULL )) == -1 )

{

printf ( "Error exec'ing child; ERRNO: %d\n", errno ) ;

}

}

Additional reference words: 5.10 6.00 6.00a 6.00ax 7.00