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
> 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/manual/html_node/Job-Control.html#Job-Control
is good reading.
This doesn't appear to work if the terminal is a nologin window.
[cdalten@localhost oakland]$ more me.c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
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]$