[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in exit()?
From: |
Michael Kerrisk |
Subject: |
Re: Bug in exit()? |
Date: |
Tue, 24 Apr 2001 13:47:12 +0200 |
Gidday Andres,
> > I've tested the following with glibc 2.1.3 (Linux kernel 2.2.14,
> > SuSE6.4), but looking at the sources of glibc 2.2.3pre1, things don't
> > look the same.
> >
> > Ths is rather a "philosophical" bug report. The exit() function does not
> > appear to close stdio streams, although SUSv3 and Austin do specifythis.
> > I discovered this while checking out some behaviours of vfork() - in a
> > vforked child, I did an exit(), and found that the standard I/O streams
> > *weren't* closed in the parent process when it resumed.
> >
> > I assume there are reasons things are done this way. Are there plans to
> > change this behaviour?
>
> Do you have a sample program that shows the problem?
Okay, one supplied below. However, I've been looking at the glibc source,
and as far as I can see it really looks as though __close() is not called
on the opern streams when exit() is used...
In the supplied program, the vfork()ed child runs in its parent's address
space (test on SuSE 6.4, Kernel 2.2.14, glibc 2.2.3), and so its call to
exit should close the parent's stdout buffer, and cause the printf() in
the parent to fail. Instead the printf() succeeds. Uncommenting the
fclose() in the child achieves the effect that should be achieved just by
the child calling exit().
Cheers
Michael
------------------------------------------
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
int s;
switch (vfork()) {
case -1:
perror("vfork");
exit(EXIT_FAILURE);
case 0: /* Child executes first, in parent's memory space */
/* fclose(stdout); */ /* Uncommenting this really does stop
printf() in the parent from working */
exit(EXIT_SUCCESS); /* This should flush *and* close stdout */
default: /* Parent is blocked until child exits */
s = printf("Hello world\n");
exit((s == -1) ? EXIT_FAILURE : EXIT_SUCCESS);
} /* switch */
} /* main */
__________________________________________
Michael Kerrisk
mailto: address@hidden
"Opportunities to rise are no substitute for a general
diffusion of the means of civilisation."
R. H. Tawney, 'Equality'
- Bug in exit()?, Michael Kerrisk, 2001/04/24
- Re: Bug in exit()?, Andreas Jaeger, 2001/04/24
- Re: Bug in exit()?,
Michael Kerrisk <=
- Re: Bug in exit()?, Wolfram Gloger, 2001/04/24
- Re: Bug in exit()?, Michael Kerrisk, 2001/04/24
- Re: Bug in exit()?, Ulrich Drepper, 2001/04/24
- Re: Bug in exit()?, Michael Kerrisk, 2001/04/25
- Re: Bug in exit()?, Ulrich Drepper, 2001/04/25
- Re: Bug in exit()?, Mike Castle, 2001/04/25
- Re: Bug in exit()?, Ulrich Drepper, 2001/04/25
- Re: Bug in exit()?, Wolfram Gloger, 2001/04/25