16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 43. Pushing a Module onto a Stream<br />

I/O Subsystem<br />

Figure 44. Windowing VT<br />

on Physical Terminal<br />

/* assume file descriptors 0 and 1 already refer to physical tty */<br />

for (;;) /* loop */<br />

{<br />

select (input); /* wait for some line <strong>with</strong> input */<br />

read input line;<br />

switch (line <strong>with</strong> input data)<br />

{<br />

case physical tty: /* input on physical tty line */<br />

if (control command) /* e.g. create new window */<br />

{<br />

open a free pseudo-tty;<br />

fork a new process:<br />

if (parent)<br />

{<br />

push a msg discipline on mpx side;<br />

continue; /* back to for loop */<br />

}<br />

/* child here */<br />

close unnecessary file descriptors;<br />

open o<strong>the</strong>r member of pseudo-tty pair, get stdin, stdout, stderr;<br />

push tty line discipline;<br />

exec shell; /* looks like virtual tty */<br />

}<br />

/* "regular" data from tty coming up for virtual tty */<br />

demultiplex data read from physical tty,<br />

strip off headers and write to appropriate pty;<br />

continue; /* back to for loop */<br />

case logical tty: /* a virtual tty is writing a window */<br />

encode header indicating what window data is for;<br />

write header and data to physical tty;<br />

continue; /* back to for loop */<br />

}<br />

}<br />

Figure 45. Pseudo-code for<br />

Multiplexing Windows<br />

152

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!