[cw]
/*
 * 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 != open)
        {
            /*
             * lose controlling terminal
             */
            ioctl(fd, TIOCNOTTY, 0);
            close(fd);
        }
    }
#endif

#ifdef SVR4
    /*
     * change process group AND lose controlling terminal
     */
    setpgrp();
#endif
[ecw]

<B>Listing 2. Daemon code for systems not supporting [cw]setsid()[ecw].<B>
