From: Roman Prokhorov <roma@stalker.gamma.ru>
Subject: Re: fork() problem
Date: Thu, 29 Aug 2002 19:00:02 +0400 [thread overview]
Message-ID: <roma-25B57C.19000129082002@news.gamma.ru> (raw)
In-Reply-To: m3bs7m73wa.fsf@salmon.parasoft.com
In article <m3bs7m73wa.fsf@salmon.parasoft.com>,
Paul Pluzhnikov <ppluzhnikov@earthlink.net> wrote:
> Roman Prokhorov <roma@stalker.gamma.ru> writes:
>
> > I have a problem: Under Tru64 the fork() called from a thread freezes.
> > This doesn't happen on the other Unixes I tried. See my code below, did
> > I do anything wrong?
>
> Yes.
>
> Your question has been answered many times in comp.programming.threads.
> Search groups.google.com for "thread fork async" ...
>
> Here is one answer by Kaz Kylheku
> Message-ID: <slrn8urucn.gqp.kaz@ashi.FootPrints.net>
>
> Mind you, according to POSIX, if a threaded process forks a
> child, that child can execute only async safe functions. It
> can use exec() to load a new process image. Since fprintf()
> is not async safe, calling it results in undefined behavior.
>
> Cheers,
Thanks for the tip about async safe functions. However it didn't help.
What's wrong now? I don't use printf in the thread at all, but fork()
still doesn't invoke unless I call sleep().
---------
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include <sys/types.h>
#include<unistd.h>
void func(void *pData) {
if(fork()==0) {
char *const args[]={"/usr/bin/ls","-al",NULL};
execvp("/usr/bin/ls",args);
_exit(0);
} else {
}
}
main() {
char buf[10];
pthread_t theThread;
if(!pthread_create(&theThread,NULL,(void *(*)(void *))&func,NULL)) {
pthread_detach(theThread);
} else {
printf("Unable to launch a thread\n");
}
printf("hit Enter, please\n");
fgets(buf,sizeof(buf),stdin);
//sleep(1);
printf("hit Enter again, please\n");
fgets(buf,sizeof(buf),stdin);
}
--
Roman
next prev parent reply other threads:[~2002-08-29 15:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-28 23:13 fork() problem Roman Prokhorov
2002-08-29 4:04 ` Paul Pluzhnikov
2002-08-29 15:00 ` Roman Prokhorov [this message]
2002-08-30 0:05 ` Paul Pluzhnikov
2002-08-30 12:28 ` Roman Prokhorov
2002-08-30 15:04 ` Paul Pluzhnikov
2002-08-30 16:41 ` Roman Prokhorov
2002-08-30 18:04 ` Paul Pluzhnikov
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox