Re: Help on fork()
Re: Help on fork()
- Subject: Re: Help on fork()
- From: Arnab Ganguly <email@hidden>
- Date: Mon, 11 May 2009 20:30:16 +0530
Hi All,
How do I kill a thread without affecting the process.I tired pthread_kill function with SIGKILL and SIGINT, it is affecting the process.
I have thread 1 executing some function, when thread 2 is launched I need to stop the thread and let thread 2 execute only.Any suggestion would be of great help.I need to take care of the resources thread1 using before I stop it.
Thanks
Arnab
On Mon, May 11, 2009 at 4:20 PM, Jean-Daniel Dupas
<email@hidden> wrote:
Le 11 mai 09 à 12:44, Arnab Ganguly a écrit :
Hi All,
I am trying to some processing after calling fork() == 0.But when it enters in to this children loop I get the following error.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
Anybody came across similar issues ?
What would be the work around for this?
Thanks in advance
CoreFoundation and fork()
Due to the behavior of fork(), CoreFoundation cannot be used on the child-side of fork(). If you fork(), you must follow that with an exec*() call of some sort, and you should not use CoreFoundation APIs within the child, before the exec*(). The applies to all higher-level APIs which use CoreFoundation, and since you cannot know what those higher-level APIs are doing, and whether they are using CoreFoundation APIs, you should not use any higher-level APIs either. This includes use of the daemon() function.
Additionally, per POSIX, only async-cancel-safe functions are safe to use on the child side of fork(), so even use of lower-level libSystem/BSD/UNIX APIs should be kept to a minimum, and ideally to only async-cancel-safe functions.
This has always been true, and there have been notes made of this on various Cocoa developer mailling lists in the past. But CoreFoundation is taking some stronger measures now to "enforce" this limitation, so we thought it would be worthwhile to add a release note to call this out as well. A message is written to stderr when something uses API which is definitely known not to be safe in CoreFoundation after fork(). If file descriptor 2 has been closed, however, you will get no message or notice, which is too bad. We tried to make processes terminate in a very recognizable way, and did for a while and that was very handy, but backwards binary compatibility prevented us from doing so.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden