Facebook Twitter Instagram
    WiredRevolution.com
    • Home
    • About
    • Contact Us
    • Essential Linux Commands
    • Sitemap
    Facebook Twitter Instagram
    WiredRevolution.com
    C

    Find controlling terminal with ttyname

    RyanBy RyanNovember 6, 2008Updated:November 6, 20081 Comment1 Min Read
    Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Email

    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
    
    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Email
    Previous ArticleSet DHCP timeout in Gentoo
    Next Article Command substitution in BASH

    Related Posts

    Echo text without a trailing newline

    How to SSH into Ubuntu LiveCD

    Find IP address from remote end of a TCP socket

    Most Commented
    March 12, 2009

    Fix blue tinted video in Ubuntu

    September 10, 2010

    Setup SSH access between VirtualBox Host and Guest VMs

    March 8, 2011

    Install GNOME Shell in Ubuntu 10.10 Maverick

    April 4, 2009

    Setup the PS3 Bluetooth Controller on Ubuntu

    October 22, 2008

    How to correctly use LD_LIBRARY_PATH

    Recent Comments
    • Execute command on linux virtual machine (or server) from windows commandline on Setup SSH access between VirtualBox Host and Guest VMs
    • Solved: How to SSH to a VirtualBox guest externally through a host? - Daily Developer Blog on Setup SSH access between VirtualBox Host and Guest VMs
    • How to SSH to a VirtualBox guest externally through a host? [closed] – Code D3 on Setup SSH access between VirtualBox Host and Guest VMs
    • How to copy and paste from VirtualBox? [duplicate] on Setup SSH access between VirtualBox Host and Guest VMs
    • Jackie Laguna on Fix OpenGL: ChoosePixelFormat SketchUp error in WINE
    © 2026 ThemeSphere. Designed by ThemeSphere.

    Type above and press Enter to search. Press Esc to cancel.