Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Controlling terminal questions

2 views
Skip to first unread message

Boltar

unread,
Oct 1, 2008, 6:11:02 AM10/1/08
to
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

Nate Eldredge

unread,
Oct 1, 2008, 5:36:59 PM10/1/08
to
Boltar <bolta...@yahoo.co.uk> 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/manual/html_node/Job-Control.html#Job-Control
is good reading.

K-mart Cashier

unread,
Oct 1, 2008, 11:43:48 PM10/1/08
to
On Oct 1, 2:36 pm, Nate Eldredge <n...@vulcan.lan> wrote:

> Boltar <boltar2...@yahoo.co.uk> 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 <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]$


0 new messages