fork.c 842 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <grass/config.h>
  2. #include <unistd.h>
  3. #include <grass/gis.h>
  4. /*************************************************************
  5. * G_fork()
  6. *
  7. * Issue a system fork() call and protect the child from all
  8. * signals (which it does by changing the process group for the child)
  9. *
  10. * returns:
  11. * -1 fork failed.
  12. * 0 child
  13. * >0 parent
  14. ************************************************************/
  15. int G_fork(void)
  16. {
  17. #ifdef __MINGW32__
  18. return -1;
  19. #else /* __MINGW32__ */
  20. int pid;
  21. pid = fork();
  22. /*
  23. * change the process group for the child (pid == 0)
  24. * note: we use the BSD calling sequence, since
  25. * it will work ok for ATT call which has no arguments
  26. */
  27. if (pid == 0)
  28. #ifdef SETPGRP_VOID
  29. setpgrp();
  30. #else
  31. setpgrp(0, getpid());
  32. #endif
  33. return pid;
  34. #endif /* __MINGW32__ */
  35. }