简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM