- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Pseudo-terminal Utilities in Python
The Pseudo-terminal utility module pty is defined to handle pseudo-terminal concepts. Using this we can start another process, and also can read or write from controlling terminal using programs.
This module is highly platform oriented. We should use UNIX systems to perform these operations.
To use the pty module, we should import it using −
There are some modules of the pty module, these are −
This method is used to connect the child controlling terminal to pseudo-terminal. This method returns the pid and the fd. The child process gets the pid 0, but the fd is invalid. The return value of the parent is the pid of the child process and the fd holds the child controlling terminal.
This method is used to open a new pseudo-terminal pair. It returns a file descriptor for the master and the slave.
Method pty.spawn(argv[, master_read[, stdin_read]])
The spawn process is used to connect its controlling terminal with current processes standard io. The master_read and stdin_read read from the file descriptor. The default size is 1024 bytes.
import pty, os def process_parent_child(): (process_id, fd) = pty.fork() print("The Process ID for the Current process is: " + str(os.getpid())) print("The Process ID for the Child process is: " + str(process_id)) process_parent_child() master, slave = pty.openpty() print('Name of the Master: ' + str(os.ttyname(master))) print('Name of the Slave: ' + str(os.ttyname(slave)))
The Process ID for the Current process is: 12508 The Process ID for the Child process is: 12509 Name of the Master: /dev/ptmx Name of the Slave: /dev/pts/2
- How to open new pseudo-terminal pair using Python?
- How to open a new pseudo-terminal pair using Python?
- Python Utilities for with-statement contexts (contextlib)
- Terminal Control Functions in Python
- Print Colors of terminal in Python
- Formatted text in Linux Terminal using Python
- Generate pseudo-random numbers in Python
- Initialize an Array with Reflection Utilities in Java
- How to install guake drop down terminal terminal on ubuntu
- Difference Between Pseudo-Class and Pseudo-Element in CSS
- The Exposed Terminal Problem
- The Hidden Terminal Problem
- Avoid placing password on command line with MySQL Utilities?
- CSS Pseudo Elements
- Java 8 Stream Terminal Operations