delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/09/28/11:50:46

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <48DFA78A.3020506@sh.cvut.cz>
Date: Sun, 28 Sep 2008 17:49:30 +0200
From: =?UTF-8?B?VsOhY2xhdiBIYWlzbWFu?= <v DOT haisman AT sh DOT cvut DOT cz>
User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: crash if fork(2) from another thread
References: <003301c92110$336cee20$0200a8c0 AT whiterabc2znlh> <48DF3317 DOT 5060300 AT sh DOT cvut DOT cz> <20080928152527 DOT GA2219 AT ednor DOT casa DOT cgf DOT cx>
In-Reply-To: <20080928152527.GA2219@ednor.casa.cgf.cx>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Christopher Faylor wrote, On 28.9.2008 17:25:
> On Sun, Sep 28, 2008 at 09:32:39AM +0200, V??clav Haisman wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA256
>>
>> Hirokazu Yamamoto wrote, On 28.9.2008 4:16:
>>> # I've post mail, but it didn't show up in
>>> http://www.nabble.com/Cygwin-f12165.html.
>>> # Maybe it was not good to attach a file. So try again...
>>>
>>> I'm not familiar with pthread & fork, but I think following code should not
>>> crash. Is this expected behavior?
>>>
>>> #include <stdio.h>
>>> #include <stdlib.h>
>>> #include <pthread.h>
>>> #include <assert.h>
>>>
>>> void *thread_func(void* args)
>>> {
>>>     int ret;
>>>     pid_t pid;
>>>     pthread_t thread;
>>>
>>>     puts("thread_func");
>>>
>>>     pid = fork();
>>>
>>>     assert(pid != (pid_t)-1);
>>>
>>>     if (pid != 0) /* parent process */
>>>     {
>>>         int status;
>>>
>>>         printf("parent process (child pid = %d)\n", pid);
>>>
>>>         waitpid(pid, &status, 0);
>>>
>>>         puts("parent process end");
>>>     }
>>>     else /* child process */
>>>     {
>>>         puts("child process"); /* crash here */
>> I think this is not allowed in here.  You can only do async-signal-safe
>> stuff in the child.  IO is AFAIK not in that category.  Basically, the
>> only thing you can safely do in the child process is to call exec().
> 
> I don't see any reason why this shouldn't be allowed.  You should
> be able to do anything you want in a child process.
I do not think that is true. As per
<http://www.opengroup.org/onlinepubs/009695399/functions/fork.html>,
RATIONALE, the penultimate paragraph, it is basically undefined behaviour.


- --
VH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)

iFYEAREIAAYFAkjfp4oACgkQhQBMvHf/WHmFRwDgoqjd8DsvwSb8e+3BEbvYtVLK
mLXEYdMTkxauIADgsxmD6GxTDfHCyaTP41jpRkErFhTXsZ5bHcRjrg==
=hyOi
-----END PGP SIGNATURE-----

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019