[GRASS5] R_open_driver() after fork()

Eric G. Miller egm2 at jps.net
Thu Feb 13 10:58:48 EST 2003


On Thu, Feb 13, 2003 at 03:04:54PM +0100, Radim Blazek wrote:

> No, it did not help, but I was not precise enough in my first mail,
> I discovered later that the problem appeares if fork() is executed 
> when driver is opened:
> 
> R_open_driver();
> pid fork(); 
> if (pid > 0) {
>     R_close_driver();
>     R_open_driver();
> }
> 
> I can avoid this by closing monitor before fork() is called -
> but is it final solution?

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;

}

-- 
echo ">gra.fcw at 2ztr< eryyvZ .T pveR" | rot13 | reverse




More information about the grass-dev mailing list