Python pty fork()

Python pty fork()

Introduction :
The full form of pty is Pseudo Terminal Utilities. The module is defined to handle Pseudo-terminal concepts. In this, we can start another process and also can write to and read from its controlling terminal using programs.

Method Name : pty.fork()
Description : This method is one of the functions of Pseudo-Terminal.It is used for connecting the child's controlling terminal to a Pseudo-Terminal.

In this article, I will be introducing the pty.fork() module.

The method returns the pid and fd. The child gets the pid value 0 and fd is invalid.The parent's return value is the pid of the child process and fd is the file descriptor which is connected to the child's controlling terminal.

The main thing in this process is that of using pty.fork() is the returned pseudoterminal(pty) file descriptor is read by the parent process .

The first step would be to import the pty module.  
cmd command:
 import pty.fork()

Example :
Code :
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)))