[GRASS5] R_open_driver() after fork()
Eric G. Miller
egm2 at jps.net
Thu Feb 13 06:34:30 EST 2003
On Thu, Feb 13, 2003 at 11:23:29AM +0100, Radim Blazek wrote:
> Hi,
>
> I have one problem: if module creates child process by fork(),
> it is impossible open driver by R_open_driver() in parent.
> In sync_driver() it hangs on read(). SIGALRM is recieved and dead()
> executed, but module doesn't continue in execution - still hanging on read(),
> until child is killed.
The following seems to work okay for me. Perhaps you are trying to have
both parent and child connected to the same server at the same time?
The display server architecture only will process one connection at a
time.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include "gis.h"
int main (int argc, char *argv[])
{
pid_t pid;
G_gisinit(argv[0]);
if ((pid = fork()) == 0) {
/* child */
sleep(5);
} else if (pid > 0) {
/* parent */
if (R_open_driver() == 0) {
fprintf (stderr, "Driver Opened\n");
R_close_driver();
fprintf (stderr, "Driver Closed\n");
} else {
/* failed to open driver ... */
G_fatal_error("Failed to open driver\n");
}
} else {
/* fork() failed */
G_fatal_error ("Fork failed!\n");
}
if (pid > 0) {
int status;
waitpid (pid, &status, 0);
}
return 0;
}
--
echo ">gra.fcw at 2ztr< eryyvZ .T pveR" | rot13 | reverse
More information about the grass-dev
mailing list