public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Usage of _exit(0) closes fd's of parent process
@ 2010-04-11  5:49 tmhikaru
  2010-04-11  6:29 ` Christopher Faylor
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: tmhikaru @ 2010-04-11  5:49 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1129 bytes --]

	Hi. I'm having an unusual problem in a program I'm trying to get
working in cygwin. My program fork()'s a child process to do a hostname
lookup, establishes a tcp connection in the parent, then has the child
_exit(0) itself. For some reason I don't understand, _exit is not just
closing the fd's of the child, but of the parent as well. From my
understanding, _exit is supposed to close the fd's of the process it is run
from only.

	The program works correctly (That is to say, stays connected) if I
comment out the _exit and instead have it while (1) { sleep (10000); }.
Obviously I would like to be able to kill off the child at some point, but
for testing this proved to me that either my expectation of how _exit is
supposed to work in cygwin is flawed, or _exit is.

	Please let me know if I'm using this function call incorrectly, and
what behavior I should be expecting. If my expectation of how _exit is
supposed to act is correct, let me know and I'll file a bug report.


	I am not subscribed to the cygwin mailing list, so please make sure
replies are sent to my email address as well as the list.

Thank you,
Hikaru

[-- Attachment #2: Type: application/pgp-signature, Size: 481 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Usage of _exit(0) closes fd's of parent process
  2010-04-11  5:49 Usage of _exit(0) closes fd's of parent process tmhikaru
@ 2010-04-11  6:29 ` Christopher Faylor
  2010-04-11 11:30   ` Dave Korn
  2010-04-12  1:11 ` tmhikaru
  2010-04-13  2:17 ` tmhikaru
  2 siblings, 1 reply; 7+ messages in thread
From: Christopher Faylor @ 2010-04-11  6:29 UTC (permalink / raw)
  To: cygwin

On Sun, Apr 11, 2010 at 01:48:51AM -0400, tmhikaru@gmail.com wrote:
>Hi.  I'm having an unusual problem in a program I'm trying to get
>working in cygwin.  My program fork()'s a child process to do a
>hostname lookup, establishes a tcp connection in the parent, then has
>the child _exit(0) itself.  For some reason I don't understand, _exit
>is not just closing the fd's of the child, but of the parent as well.
From my understanding, _exit is supposed to close the fd's of the
>process it is run from only.
>
>The program works correctly (That is to say, stays connected) if I
>comment out the _exit and instead have it while (1) { sleep (10000); }.
>Obviously I would like to be able to kill off the child at some point,
>but for testing this proved to me that either my expectation of how
>_exit is supposed to work in cygwin is flawed, or _exit is.
>
>Please let me know if I'm using this function call incorrectly, and
>what behavior I should be expecting.  If my expectation of how _exit is
>supposed to act is correct, let me know and I'll file a bug report.

While it is theoretically possible to close handles in the parent process
it would be very unsual for Cygwin, or any program, to do something like
that.  And, in fact, Cygwin doesn't try to close handles in the parent
when it exits.

You need to go back and read http://cygwin.com/problems.html and then,
take a step back, and report the problem that you're seeing rather than
your conclusions about the problem.  For instance, what does "stays
connected" mean?  Are you using sockets, pipes, a file, shared memory,
etc.?

cgf

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Usage of _exit(0) closes fd's of parent process
  2010-04-11  6:29 ` Christopher Faylor
@ 2010-04-11 11:30   ` Dave Korn
  2010-04-11 12:30     ` Corinna Vinschen
  0 siblings, 1 reply; 7+ messages in thread
From: Dave Korn @ 2010-04-11 11:30 UTC (permalink / raw)
  To: cygwin; +Cc: tmhikaru

On 11/04/2010 07:29, Christopher Faylor wrote:
> On Sun, Apr 11, 2010 at 01:48:51AM -0400, tmhikaru@gmail wrote:

>> establishes a tcp connection in the parent, 

> your conclusions about the problem.  For instance, what does "stays
> connected" mean?  Are you using sockets, pipes, a file, shared memory,
> etc.?

  Call it guesswork or an assumption if you like, but I think he's using a TCP
socket!  Wasn't there a thread like this just recently that Corinna was
helping someone with a problem and it was to do with some kind of "winsock
handles aren't quite like other handles when it comes to duplicating them"
problem?  I'll have a search through my old emails and see if I can find it.

  Hikaru, are you fully up-to-date with the latest Cygwin DLL?  And is it
possible for you to strip down your code to a tiny testcase using just the
minimal code to open the socket, accept the connection, fork the child and
call _exit, so that hopefully we can reproduce the problem?

    cheers,
      DaveK

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Usage of _exit(0) closes fd's of parent process
  2010-04-11 11:30   ` Dave Korn
@ 2010-04-11 12:30     ` Corinna Vinschen
  0 siblings, 0 replies; 7+ messages in thread
From: Corinna Vinschen @ 2010-04-11 12:30 UTC (permalink / raw)
  To: cygwin

On Apr 11 12:48, Dave Korn wrote:
> On 11/04/2010 07:29, Christopher Faylor wrote:
> > On Sun, Apr 11, 2010 at 01:48:51AM -0400, tmhikaru@gmail wrote:
> 
> >> establishes a tcp connection in the parent, 
> 
> > your conclusions about the problem.  For instance, what does "stays
> > connected" mean?  Are you using sockets, pipes, a file, shared memory,
> > etc.?
> 
>   Call it guesswork or an assumption if you like, but I think he's using a TCP
> socket!  Wasn't there a thread like this just recently that Corinna was
> helping someone with a problem and it was to do with some kind of "winsock
> handles aren't quite like other handles when it comes to duplicating them"
> problem?  I'll have a search through my old emails and see if I can find it.

None of the problems discussed was about accidental closing of handles
in parent processes.  There's a lot of weirdness in WinSock, but this
one I never encountered.

Anyway, a *simple* testcase in plain C with only the bare minimum of
code to reproduce the problem could be helpful.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Usage of _exit(0) closes fd's of parent process
  2010-04-11  5:49 Usage of _exit(0) closes fd's of parent process tmhikaru
  2010-04-11  6:29 ` Christopher Faylor
@ 2010-04-12  1:11 ` tmhikaru
  2010-04-13  2:17 ` tmhikaru
  2 siblings, 0 replies; 7+ messages in thread
From: tmhikaru @ 2010-04-12  1:11 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 502 bytes --]

	Thank you, those of you who have pointed out that _exit() is not
supposed to be doing what I think it is. I will therefore assume this is
either not a bug in my program or otherwise that it is complex enough that I
can't figure it out myself. In either case, I'll be following the bug
reporting guidelines and will post a small test case program along with it
that demonstrates the problem either tonight or tomorrow, depending on how
difficult it is for me to complete properly.

	Thank you,
	Hikaru

[-- Attachment #2: Type: application/pgp-signature, Size: 481 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Usage of _exit(0) closes fd's of parent process
@ 2010-04-13  2:17 ` tmhikaru
  2010-04-13 17:34   ` gothrog
  0 siblings, 1 reply; 7+ messages in thread
From: tmhikaru @ 2010-04-13  2:17 UTC (permalink / raw)
  To: cygwin


[-- Attachment #1.1: Type: text/plain, Size: 3076 bytes --]

	Trying to send this to the list again, this time I've made the
attachments gzipped, since the spamassassin on the cygwin mailing list
thought I was sending spam last time.

	I'm running into a serious amount of trouble making a test case that
exhibits the problem. While I do have a test case that theoretically matches
the code in my irc client, in practice the test case works where similar
code in the irc client does not. While the trigger in the irc client remains
_exit(0) and in fact a simple code fragment like this *anywhere* in the
program after a tcp connection is established will cause it to lose the
connection:

      int pid = fork ();
      if (pid == 0)
      {
         _exit (0);
      }

	The fact remains that I am unable to make a test case that exhibits
the problem. Obviously, it is not simply _exit that is causing my problem,
it must be interacting badly with something else in my program. I will keep
looking for the cause.

	Note that unlike I thought originally, this does not affect open
files, only networking connections. I'm aware these are very different sorts
of things on windows though I don't know the details, and apologize for the
confusion. Someone referred to an earlier thread where a somewhat similar
problem had been discussed before. If someone would be so kind as to either
give a URL to the thread, or the subject of the thread so I can find it
myself, I would be very appreciative.

	I am certain that I'll have to narrow things down before I can give
a useful bug report, but if you have suggestions as to what I should be
looking for as suspect code, please let me know. I apologize for not being
able to give you useful information yet.

	What I know is limited but I'll try to follow the reporting
guidelines as much as I can.

	I am using cygwin 1.7.4 on windows XP sp3

	I have attempted to google for the problem as well as search the
mailing list archives for similar problems to mine, but so far I have found
nothing.

	This client worked previously in cygwin 1.5.x, and also does in
linux. While I know that's not particularly useful information given the
changes in cygwin 1.7.x, at least it works somewhere.

	The IRC client is written using the GTK 1.2 toolkit, but uses
select() for managing the networking sockets instead of the gtk api. I do
not know if either of these could be relevant.

	Although the test case I have written functions as it should, I have
attached it in the hope someone has clues.

	I have also attached cygcheck.out as the problem reporting form
requests. I'm not sure why it says I have a 'orphaned' (whatever that means)
version of cygwin installed in C:\cygwin\home\Tim\lurc594\build - the
lurc594 directory and its subdirectories haven't existed for some time. I
did experiment at one point with different versions of cygwin dll's in that
directory which may explain why it remembers something was there.


	I am not subscribed to the mailing list, so it will take me some
time to reply to you if you do not make sure the email is also sent to me.

	Thank you for the help,
	Hikaru

[-- Attachment #1.2: cygcheck.out.gz --]
[-- Type: application/x-gunzip, Size: 43168 bytes --]

[-- Attachment #1.3: tmp.c.gz --]
[-- Type: application/x-gunzip, Size: 600 bytes --]

[-- Attachment #2: Type: application/pgp-signature, Size: 481 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Usage of _exit(0) closes fd's of parent process
  2010-04-13  2:17 ` tmhikaru
@ 2010-04-13 17:34   ` gothrog
  0 siblings, 0 replies; 7+ messages in thread
From: gothrog @ 2010-04-13 17:34 UTC (permalink / raw)
  To: cygwin


I'm just taking a wild stab at this, but maybe the fork isn't working like
you think it should.  I know that when I use pthreads you have to specify
exactly how you expect it to split off and close.

I've heard of this type of behavior before and it all came down to how that
thread was spawned off originally.  Because it wasn't spawned properly, it
wasn't able to clean up right.

Good Luck.

Mike


-- 
View this message in context: http://old.nabble.com/Usage-of-_exit%280%29-closes-fd%27s-of-parent-process-tp28206735p28233404.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-04-13 17:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-11  5:49 Usage of _exit(0) closes fd's of parent process tmhikaru
2010-04-11  6:29 ` Christopher Faylor
2010-04-11 11:30   ` Dave Korn
2010-04-11 12:30     ` Corinna Vinschen
2010-04-12  1:11 ` tmhikaru
2010-04-13  2:17 ` tmhikaru
2010-04-13 17:34   ` gothrog

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).