开发者

How can I detect that a command completed its output in a tty?

开发者 https://www.devze.com 2023-03-18 03:55 出处:网络
I\'m studying the code of Mobile Terminal which is a command line for iPhone. The projects emulates a VT100 terminal.

I'm studying the code of Mobile Terminal which is a command line for iPhone. The projects emulates a VT100 terminal. I can monitor everything that goes through the terminal (ascii and control characters) but I can't figure out ho开发者_JAVA技巧w the terminal knows that a command completed its output. How does the terminal know when to display the prompt again ? Is there a special control character that every command sends when ending ?


To me it sounds like you're running a shell in the terminal, because a VT100 doesn't show a prompt (AFAIK).

A shell creates a child process and executes the command there. The shell then simply waits until this child process is finished and then prints its prompt again.

An exception is when the command is run in the background (some_command &), the shell doesn't wait for the child to exit and immediately prints the prompt again.

0

精彩评论

暂无评论...
验证码 换一张
取 消