Kaushik Koneru
Kaushik Koneru

Reputation: 99

C Code: To connect a pty terminal to current process to execute commands

In a Unix Process, I am planning to write code to access terminal. So, I can login to process and run few commands.

For example, I can do telnet 0:2000 to get my terminal and from there I can dump my commands to dump process information.

On my research, I saw that I can use /dev/pts or /dev/tty to the access terminal for the process. User can login to terminal to these but not clear on how it is works.

Upvotes: 2

Views: 972

Answers (1)

o11c
o11c

Reputation: 16046

To create a new pseudoterminal, tou need to call the following functions in order:

  • posix_openpt (To get a new master)

  • grantpt (To fix permissions for the new slave)

  • unlockpt (To unlock the slave)

  • ptsname (To get the name of the slave)

  • open (To open the slave)

  • setsid (optional, to enter a new session and process group - typically after fork when you are running a separate process on the slave)

Upvotes: 4

Related Questions