From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,689ead9f7415a732 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2002-08-29 08:00:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.gamma.ru!srcc!Gamma.RU!roma From: Roman Prokhorov Newsgroups: comp.unix.tru64 Subject: Re: fork() problem Date: Thu, 29 Aug 2002 19:00:02 +0400 Organization: Gamma NNTP server Moscow Russia Message-ID: References: NNTP-Posting-Host: roma.ttk.ru X-Trace: news.gamma.ru 1030633202 30720 195.170.229.76 (29 Aug 2002 15:00:02 GMT) X-Complaints-To: abuse@gamma.ru NNTP-Posting-Date: Thu, 29 Aug 2002 15:00:02 +0000 (UTC) Keywords: 318629621 Posted-And-Mailed: yes User-Agent: MT-NewsWatcher/3.1 (PPC) Xref: archiver1.google.com comp.unix.tru64:8520 In article , Paul Pluzhnikov wrote: > Roman Prokhorov 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: > > 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 #include #include #include #include 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