Linux API/linux
openpty, forkpty, login_tty
구차니
2026. 9. 9. 17:17
gpt 말로는 scanf() 같이 터미널에서 입력 받는 등, pipe 보다는 터미널의 영향을 받는 프로그램을 테스트 하기 좋다고.
forkpty는 fork + openpty 라는데 한번 둘러는 봐야겠다.
| The openpty() function finds an available pseudoterminal and returns file descriptors for the master and slave in amaster and aslave. If name is not NULL, the filename of the slave is returned in name. If termp is not NULL, the terminal parameters of the slave will be set to the values in termp. If winp is not NULL, the window size of the slave will be set to the values in winp. The login_tty() function prepares for a login on the terminal fd (which may be a real terminal device, or the slave of a pseudoterminal as returned by openpty()) by creating a new session, making fd the controlling terminal for the calling process, setting fd to be the standard input, output, and error streams of the current process, and closing fd. The forkpty() function combines openpty(), fork(2), and login_tty() to create a new process operating in a pseudoterminal. The file descriptor of the master side of the pseudoterminal is returned in amaster, and the filename of the slave in name if it is not NULL. The termp and winp arguments, if not NULL, will determine the terminal attributes and window size of the slave side of the pseudoterminal. |