ctermid() method of os module in Python

The Python method os.ctermid() returns the path corresponding to the controlling terminal of the process. The Python example shows that the special file corresponding to the controlling terminal(where the Python program is running) is /dev/tty.

Os Updated 16 Nov 2018 1 min read

Method Name

os.ctermid()

Method Signature

os.ctermid()

Method Overview

  • The method ctermid() of the os module in Python returns the filename associated with the controlling terminal of the process.
  • A controlling terminal could be any POSIX terminal, which controls a set of processes, grouped as a session on the host system. Example: A physical ASCII asynchronous terminal, like a VT-100.

Controlling Terminal

Example

python
import os

# Get the filename associated with the controlling terminal of the process

print("Filename corresponding to the  controlling terminal:")

print(os.ctermid())

Output

Output
Filename corresponding to the  controlling terminal:

/dev/tty

As per output, the path name or the special file that represents the controlling terminal of this process is /dev/tty.