Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* fork() problem
@ 2002-08-28 23:13 Roman Prokhorov
  2002-08-29  4:04 ` Paul Pluzhnikov
  0 siblings, 1 reply; 8+ messages in thread
From: Roman Prokhorov @ 2002-08-28 23:13 UTC (permalink / raw)


Hi,

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? 

I discovered that I can unfreeze the fork() when I call sleep() from the 
main thread. What sleep() realy does?


#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include <sys/types.h>
#include<unistd.h>

void fork_handler1() {
  printf("prepare handler called\n");
}
void fork_handler2() {
  printf("parent handler called\n");
}
void fork_handler3() {
  printf("child handler called\n");
}


void func(void *pData) {

 pthread_atfork(fork_handler1,fork_handler2,fork_handler3); 
 printf("thread launched\n");

 if(fork()==0) {
   printf("new fork started, pid=%d\n",getpid());
   exit(0);
 } else {
   printf("old fork running, pid=%d\n",getpid());
 }
}


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


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

end of thread, other threads:[~2002-08-30 18:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-28 23:13 fork() problem Roman Prokhorov
2002-08-29  4:04 ` Paul Pluzhnikov
2002-08-29 15:00   ` Roman Prokhorov
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox