generate the pathname of the current controlling terminal
#include <stdio.h> char *ctermid( char *s );
The ctermid() function generates a string that contains the pathname of the current controlling terminal for the calling process.
If the argument s is NULL, the string is built in a static buffer and a pointer to the buffer is returned.
If the argument s isn't NULL, the pathname is placed in that string. This string should be at least L_ctermid characters long (see <stdio.h>).
A pointer to the pathname of the controlling terminal, or a pointer to a null string if the function was unable to locate the controlling terminal,
#include <stdio.h> int main( void ) { printf( "Controlling terminal is %s\n", ctermid( NULL ) ); return( EXIT_SUCCESS ); }
POSIX 1003.1
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |
If the s parameter is NULL, this function isn't signal-handler-safe or thread-safe.
setsid(), tcsetct(), ttyname()