Subj : Re: Problem with system() calls in a multithreaded program on HPUX 11 To : comp.programming.threads,comp.sys.hp.hpux From : maheshkumarjha Date : Sun Feb 13 2005 11:09 pm ptjm@interlog.com (Patrick TJ McPhee) wrote in message news:<37a1suF55hncsU2@uni-berlin.de>... > In article , > Paul Pluzhnikov wrote: > % maheshkumarjha@gmail.com (Mahesh Kumar) writes: > % > % > I am porting a multithreaded program to HPUX 11 from Solaris, in > % > which threads make calls to system() functions. > % > % This is extremely bad idea (TM). > % > % Writing multithreaded programs that fork() correctly requires > % careful use of pthread_atfork handlers for every possible lock used, > % both in your code and in every library you link against. > > I'd say that atfork handlers are largely useless. Whatever you do with > mutexes, for instance, is irrelevant because the child process isn't > allowed to lock or unlock them anyway. execing a new process image is > allowed, though. system() is problematic, but the problem is with > waiting for the child process to finish, rather than with forking and > execing. Well, just to make sure that there was no problem with fork and wait, I tried replacing system() function call with following, int my_system (char *command) { int status; if (command == 0) return 1; pid_t pid = fork(); if (pid == -1) return -1; if (pid == 0) { char *argv[4]; argv[0] = "sh"; argv[1] = "-c"; argv[2] = command; argv[3] = NULL; execve("/bin/sh", argv, environ); exit(127); } do { if (waitpid(pid, &status, 0) == -1) { if (errno != EINTR) return -1; } else return status; } while(1); } But still it hanged when I tried to run it for 6 threads. (I already said number of threads is not consistent.) The only difference being that there were no processes this time. Can anyone suggest a possible reason for still hanging? Thanks and regards. Mahesh Kumar .