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

Last reviewed: July 17, 1997
Article ID: Q58779
5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS                      | WINDOWS
kbprg kbbuglist

The information in this article applies to:

  • The C Run-time (CRT), included with:

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

SYMPTOMS

In Microsoft C, modifying the C Run-time startup code to increase the maximum number of open file handles and streams can cause a program that does multiple exec's to hang.

CAUSE

There is a known incompatibility between changing the startup source code for the C run-time library and exec'ing multiple child processes.

STATUS

Microsoft has confirmed this to be a problem in the products and versions listed above. We are researching this problem and will post new information here in the Microsoft Knowledge Base 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

/* Compile options needed: none
*/

#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 exec 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 1.00 1.50
P_OVERLAY SPAWN
KBCategory: kbprg kbbuglist
KBSubcategory: CRTIss
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.