Terminals and Processes
Posted: Mon May 28, 2012 2:09 am
Greetings everyone,
I have some theoretical questions about terminals and processes. Let's assume the following environment:
Suppose that an OS has one terminal for the whole system which processes can connect on it. Initially, there is only one process in the system (let's call it process0) and that is, by the way, connected on the terminal.
For instance, process0 will be (always) the "active process" (process that is interacting with the user) and every time that a keyboard key has been pressed, it will be put in a "tty read queue" that process0 can read.
After some execution, at some point process0 decided to create a child process (process1):
As illustrated above, after the fork() system call, both processes (process0, process1) perform I/O operations on the terminal.
Regarding this situation my questions are:
Question 1: Each process has to have its own "tty read queue" and "tty write queue" or can be one of them per terminal?
Question 1 Remark: It seems to me if each process has its own queues, some race conditions can be avoid and therefore, the terminal implementation can be more secure and parallel. However, if each process has its own tty queues this is a BIG waist of memory.
Question 2: As I said above, the keyboard keys which have been pressed are copied to a "tty read queue" and the active process can somehow read them. When there are two processes "running" in a terminal (like the example above) and there is no way to decide which process is the "background process" (process were not created like process1 & process0), every time that a process is scheduled to be executed it becomes the "active process". If so, a big messy comes in, because the keyboard driver will put the pressed keys on the "tty read queue" of the active process. However, maybe the "active process" is not waiting any keyboard input but another process, that is the really active process (process that is interacting with the user), is. The question is: how is it possible to decide which is the "active process" in this situation?
I hope that you get the questions.
Thanks in advance,
Pedro H. Penna
I have some theoretical questions about terminals and processes. Let's assume the following environment:
Suppose that an OS has one terminal for the whole system which processes can connect on it. Initially, there is only one process in the system (let's call it process0) and that is, by the way, connected on the terminal.
For instance, process0 will be (always) the "active process" (process that is interacting with the user) and every time that a keyboard key has been pressed, it will be put in a "tty read queue" that process0 can read.
After some execution, at some point process0 decided to create a child process (process1):
Code: Select all
void process0()
{
// Process0 is performing I/O operations on the terminal.
if fork()
{
// Process0 is performing I/O operations on the terminal.
}
else
{
// Process1 is performing I/O operations on the terminal.
}
}
Regarding this situation my questions are:
Question 1: Each process has to have its own "tty read queue" and "tty write queue" or can be one of them per terminal?
Question 1 Remark: It seems to me if each process has its own queues, some race conditions can be avoid and therefore, the terminal implementation can be more secure and parallel. However, if each process has its own tty queues this is a BIG waist of memory.
Question 2: As I said above, the keyboard keys which have been pressed are copied to a "tty read queue" and the active process can somehow read them. When there are two processes "running" in a terminal (like the example above) and there is no way to decide which process is the "background process" (process were not created like process1 & process0), every time that a process is scheduled to be executed it becomes the "active process". If so, a big messy comes in, because the keyboard driver will put the pressed keys on the "tty read queue" of the active process. However, maybe the "active process" is not waiting any keyboard input but another process, that is the really active process (process that is interacting with the user), is. The question is: how is it possible to decide which is the "active process" in this situation?
I hope that you get the questions.
Thanks in advance,
Pedro H. Penna