Find controlling terminal with ttyname

by
on
November 6, 2008

You can identify the path the the controlling terminal device path for your current process in C with the ttyname() system call. This controlling terminal can be a virtual console (/dev/ttyn) or a pseudo-terminal (/dev/pts/n).

The ttyname system call takes the following format.

char *ttyname(int fd);

The stdin, stdout, stderr file descriptors unless redirected are by default mapped to the controlling terminal. So for example you can pass it the stdin file descriptor.

char * pathname;
pathname = ttyname(0);

printf("controlling terminal : %s\n", pathname);
controlling terminal : /dev/pts/0

No Comments
C
, , , , , , , , , , , ,

Related posts:

  1. I/O redirection in BASH
  2. Format output using printf
  3. Display hostname and IP address in C
  4. Find IP address from remote end of a TCP socket
  5. Have a Bash script determine it’s own location

Comments (0)

No comments yet

Trackbacks (0)

No trackbacks yet

Leave a Comment

(displayed with your post)
(will not be published)
(optional)

Copyright 2008-2010 WiredRevolution.com. All rights reserved.