don@seila.UUCP (Don Kossman) (03/31/89)
Anyone seen this? What are we doing wrong/not doing? We have a problem when we fork/exec a child process from an X-window application event loop. The parent process will not exit() after the fork; it behaves as if there were a wait() statement (or something else) causing it to wait until the child process exits. In our case, we are forking and exec'ing a process which runs a converted bitmap through a print formatter and sends it to a printer. This takes quite a while and we want to run it in the background, without the user having to wait. Environment: Ultrix 3.0, UWS 2.0, Vaxstation 2000, X11 as distributed by DEC with UWS. simplified example follows... ----------------------------------------------------------------- main() { Xopendisplay Xmapwindow( sample_window) while (1) { XNextEvent (display, &report); switch (report.type) { case Expose: Xlib calls to draw on the sample_window; break; case ConfigureNotify: get width and height of the new resized window; break; case ButtonPress: dump sample_window image to an image file; /* child process */ if ( (pid = fork() == 0) { execlp("sh", "sh", "-c", command, (char *) 0); /* "command" is a shell script to print the image file and then clean up */ } /* parent process */ ? ---> exit(1); /* We want the sample_window to disappear right after the fork/exec, but (?) the exit() does not run till after the child process exits. */ default: break; } } } -- Don Kossman, SEI Information Technology, Los Angeles ...sun!tsunami!seila!don, -OR- mahendo.jpl.nasa.gov!jplgodo!seila!don