Nonblocking IO (ITI8510): erinevus redaktsioonide vahel

Allikas: Lambda
Mine navigeerimisribale Mine otsikasti
Resümee puudub
 
8. rida: 8. rida:




= 2. Nonblocking on FIFO =
= 2. Nonblocking reading from a FIFO =


Goal: To write a program which prints a '.' character every half-a second unless some input is provided on a fifo file.
Goal: To write a program which prints a '.' character every half-a second unless some input is provided on a fifo file.


Hints: Use open() with O_NONBLOCK flag, [http://en.wikipedia.org/wiki/Named_pipe fifo] can be made with a 'mkfifo fifoname' command and written to using 'cat > fifoname'.
Hints: Use open() with O_NONBLOCK flag, [http://en.wikipedia.org/wiki/Named_pipe fifo] can be made with a 'mkfifo fifoname' command and written to using 'cat > fifoname'.

Redaktsioon: 18. veebruar 2010, kell 16:46

We have two tasks today. Both with practicing nonblocking IO.

1. Canonical mode

Goal: To write a program which echoes characters on screen while typed until button 'q' is pressed. Then prints a newline.

Methods: try to put the terminal into noncanonical mode. See 'man termios'. Note that you should restore the terminal mode before quitting since otherwise the terminal gets messed up.


2. Nonblocking reading from a FIFO

Goal: To write a program which prints a '.' character every half-a second unless some input is provided on a fifo file.

Hints: Use open() with O_NONBLOCK flag, fifo can be made with a 'mkfifo fifoname' command and written to using 'cat > fifoname'.