#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

int main(void) {
    int fd, r;

    fd = open("/dev/tty", O_RDWR);
    if (fd != 0) {

        r = tcsetpgrp(fd, getpgrp());
        if (r == -1) {
            fprintf(stderr, "tcsetpgrp failed: %s\n", strerror(errno));
            return 1;
        }
    }

    printf("foreground process group is now %d\n", getpgrp());
    return 0;
}
