Listing 2. Daemon Code for Systems Not Supporting setsid()

/*
 * Listing 2:
 * change process group for systems without
 * sessions
 * Ivan Griffin (ivan.griffin@ul.ie)
 */
#ifdef BSD
    {
        int fd;
        setpgrp(0, getpid());  /* change process
            * group */
        /*
         * open controlling terminal
         */
        fd = open("/dev/tty", O_RDWR);
        if (-1 != fd)
        {
            /*
             * lose controlling terminal
             */
            ioctl(fd, TIOCNOTTY, 0);
            close(fd);
        }
    }
#endif
#ifdef SVR4
    /*
     * change process group AND lose controlling
     * terminal */
    setpgrp();
#endif