Controlling terminal questions - Unix

This is a discussion on Controlling terminal questions - Unix ; Hi On Linux how can I find out the name of a processes controlling terminal? You have to give an open file descriptor to ttyname() so I can't use that. Also , how can I change the controlling terminal to ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Controlling terminal questions

  1. Controlling terminal questions

    Hi

    On Linux how can I find out the name of a processes controlling
    terminal? You have to give an open file descriptor to ttyname() so I
    can't use that.

    Also , how can I change the controlling terminal to point to a pseudo
    tty slave that I've opened?

    Thanks for any help

    B2003

  2. Re: Controlling terminal questions

    Boltar writes:

    > Hi
    >
    > On Linux how can I find out the name of a processes controlling
    > terminal? You have to give an open file descriptor to ttyname() so I
    > can't use that.


    /dev/tty is your controlling terminal. You could open that and then
    pass it to ttyname() to get its "true name".

    > Also , how can I change the controlling terminal to point to a pseudo
    > tty slave that I've opened?


    http://www.gnu.org/software/libc/man...ml#Job-Control
    is good reading.

  3. Re: Controlling terminal questions

    On Oct 1, 2:36 pm, Nate Eldredge wrote:
    > Boltar writes:
    > > Hi

    >
    > > On Linux how can I find out the name of a processes controlling
    > > terminal? You have to give an open file descriptor to ttyname() so I
    > > can't use that.

    >
    > /dev/tty is your controlling terminal. You could open that and then
    > pass it to ttyname() to get its "true name".
    >


    This doesn't appear to work if the terminal is a nologin window.

    [cdalten@localhost oakland]$ more me.c
    #include
    #include
    #include
    #include
    #include
    #include

    int main(void)
    {
    int fd;
    char *name;

    if ((fd = open("/dev/tty", O_RDONLY)) < 0) {
    fprintf(stderr, "open error\n");
    exit(1);
    }

    name = ttyname(fd);
    printf("real ttyname is: %s\n", name);

    close(fd);
    exit(0);
    }

    [cdalten@localhost oakland]$ gcc -g me.c -o me
    [cdalten@localhost oakland]$ ./me
    real ttyname is: /dev/tty
    [cdalten@localhost oakland]$ tty
    /dev/pts/3
    [cdalten@localhost oakland]$



+ Reply to Thread