[GRASS5] R_open_driver() after fork()

Radim Blazek blazek at itc.it
Thu Feb 13 11:18:14 EST 2003


Yes, this works, but in fact I do not call fork() directly in module.
I call F_open() to open GUI form and this function creates child,
so child doesn't know if driver is open. 
Can I get info if driver is open?

Radim

On Thursday 13 February 2003 04:58 pm, Eric G. Miller wrote:
> Maybe, just call R_close_driver() in the process that won't be using it.
>
> #include <stdio.h>
> #include <unistd.h>
> #include <sys/types.h>
> #include <sys/wait.h>
> #include "gis.h"
> #include "raster.h"
>
> int main (int argc, char *argv[]) {
>
>    pid_t pid;
>    G_gisinit(argv[0]);
>
>    if (R_open_driver() != 0) {
>        G_fatal_error ("R_open_driver");
>    }
>    if ((pid = fork()) ==  0) {
>         /* child */
>         R_close_driver();
>         fprintf (stderr, "Driver Closed in child\n");
>         sleep(5);
>    } else if (pid > 0) {
>         /* parent */
>        if (R_color(1) == 0) {
>            fprintf (stderr, "R_color(1) called in parent\n");
>        } else {
>            fprintf (stderr, "R_color(1) failed\n");
>        }
>        R_close_driver();
>    } else {
>        /* fork() failed */
>        G_fatal_error ("Fork failed!\n");
>    }
>
>    if (pid > 0) {
>        int status;
>        waitpid (pid, &status, 0);
>    }
>
>    return 0;
>
> }




More information about the grass-dev mailing list