Process specific IO
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
Process specific IO
I arrived at a question today while working on some init code and hadn't wrote the forking properly. As a result it executed the shell twice, making the commands not work.
Anyway, my question:
Is there a specific or known-good way to distinguish between 2 programs wanting input?
Say each call gets() at the same time. Each process is reading port 64 or whatever at the same time. Therefor the data that each gets is not correct.
Is there a simple way to distinguish?
-JL
Anyway, my question:
Is there a specific or known-good way to distinguish between 2 programs wanting input?
Say each call gets() at the same time. Each process is reading port 64 or whatever at the same time. Therefor the data that each gets is not correct.
Is there a simple way to distinguish?
-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
-
- Member
- Posts: 190
- Joined: Tue Sep 26, 2006 1:40 pm
- Libera.chat IRC: Nokurn
- Location: Ontario, CA, USA
- Contact:
If you have two programs running and both call gets(), I would assume that you have virtual terminals, in which case you would deliver the input to the active terminal, or, more specifically, the active (foreground) process. I would recommend building this in to your keyboard driver and having the syscall interface that. Then, the driver would use the terminal driver (or process system, which would in turn use the terminal driver) to figure out what process/terminal is active, and then deliver the input there.
Just my 2c. I haven't gotten that far yet, but it's how I'd implement it once there.
Just my 2c. I haven't gotten that far yet, but it's how I'd implement it once there.
Yup - I have implemented virtual consoles and that's how I do it. You need to keep track of which console currently has 'focus' and send the keystrokes to that app. You then need some way of switching between consoles.
In the same way, you need to do this for printing on the screen, otherwise you end up with a similar problem. From my own personal experience, trying to multitask in a single console instance just creates one big mess!
Cheers,
Adam
In the same way, you need to do this for printing on the screen, otherwise you end up with a similar problem. From my own personal experience, trying to multitask in a single console instance just creates one big mess!
Cheers,
Adam
Although this suggestion will not let you access the port with 2 apps reading from there at the same time, it will create a lock so only the first shell will work.
Just a bit of psudocode there. Hopefully it will explain itself.
Code: Select all
u32int shell_running = 0;
void shell(){
if(shell_running==1){
for(;;);
} else {
shell_running=1;
}
//Shell stuff goes here
}
-
- Member
- Posts: 391
- Joined: Wed Jul 25, 2007 8:45 am
- Libera.chat IRC: aejsmith
- Location: London, UK
- Contact:
I don't quite see how that works if there are 2 separate processes, because each process will have it's own copy of the shell_running variable.
Anyway, if you do line buffering for gets in the kernel, you can put processes on a queue for lines of input. When you get a full line of input available, take the next process/thread off the queue and give it that line, then when the next line comes in give it to the next process/thread on the queue, etc.
Anyway, if you do line buffering for gets in the kernel, you can put processes on a queue for lines of input. When you get a full line of input available, take the next process/thread off the queue and give it that line, then when the next line comes in give it to the next process/thread on the queue, etc.
Hi,
I think t6q4's way is a little drastic, particularly the:
which will let the second shell start once the first shell has finished, or:
which (if you have written an exit system call) will exit subsequant shells. I still think giving one console 'focus' is the best idea, though.
Cheers,
Adam
I think t6q4's way is a little drastic, particularly the:
which will lock indefinitely if there is a shell instance already running (once you get in to that for(;;) loop). If you wanted this approach (allow just one shell running at a time), it would be better to use either:t6q4 wrote:Code: Select all
if(shell_running==1){ for(;;); } else { shell_running=1; }
Code: Select all
while(shell_running==1);
Code: Select all
if(shell_running==1) exit();
Cheers,
Adam
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
My solution (came up at a party, as most of my ideas come from a little alcohol):
It does work. Of course, I had to modify a bunch of tasking code to fit it, but it works now.
-JL
Code: Select all
getch() {
while(!get_kb_ok || (current_task!=focused_task)
{
hlt();
}
get_kb_ok=0;
/* Do getch() code here */
get_kb_ok=1;
return key_press;
}
-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Never seen such a solution.
I'm doing it by the use of the console driver and dedicated console-nodes in the VFS. There's a flow of communication between fs-service and console driver of course.
So, if f. ex. console 3 is active (in text mode - gui mode works completely different), it is marked active inside the driver which then sends keys to the according endpoint, which is registered in the file system service.
File system service knows who's reading on that special node currently (only one at a time permitted) and sends the input to that task.
End of problem. This model works without special hlt() or loops. Just look who's sitting there waiting for keys. It comes along in different shapes: synchrounous, async, buffered, nonbuffered, what so ever.
Microkernels are cool. *gg*
I'm doing it by the use of the console driver and dedicated console-nodes in the VFS. There's a flow of communication between fs-service and console driver of course.
So, if f. ex. console 3 is active (in text mode - gui mode works completely different), it is marked active inside the driver which then sends keys to the according endpoint, which is registered in the file system service.
File system service knows who's reading on that special node currently (only one at a time permitted) and sends the input to that task.
End of problem. This model works without special hlt() or loops. Just look who's sitting there waiting for keys. It comes along in different shapes: synchrounous, async, buffered, nonbuffered, what so ever.
Microkernels are cool. *gg*
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
- einsteinjunior
- Member
- Posts: 90
- Joined: Tue Sep 11, 2007 6:42 am
Why not force each application to create some sort of console handle.
Then your keyboard driver should send the data to the app having focus at the time and also using the console handle that uniquely identifies the console of the application.Moreover,with this concept,an application could have more than one console where is can receive input.
Then your keyboard driver should send the data to the app having focus at the time and also using the console handle that uniquely identifies the console of the application.Moreover,with this concept,an application could have more than one console where is can receive input.
if you open a terminal(a virtual terminal or a physical terminal or any terminal) on linux, and run python then fork it, each python process gets any of the characters you typed. This is not really an answer but rather some insight into how a very popular operating system handles it. Personally for me, if having each program get garbage input worked for linux, then i'm sure it will be more than enough for me.