Launching a signal handler for I / O

Using C on Linux, how can I run a signal handler every time I write data to the buffer using the write () function. The handler will read all the data written to the buffer at runtime.

+3
source share
4 answers

Sockets support this by activating async mode in the socket file descriptor. On Linux, this is done using fcntl calls:

/* set socket owner (the process that will receive signals) */
fcntl(fd, F_SETOWN, getpid());

/* optional if you want to receive a real-time signal instead of SIGIO */
fnctl(fd, F_SETSIG, signum);

/* turn on async mode -- this is the important part which enables signal delivery */
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_ASYNC);
+4
source

Use pipe()with O_ASYNC, and you will get SIGIOon the read end of the pipe whenever new data about the pipe.

+2
source

100% , , select , . , /. / -.

+2

write() FIFO, pipe ( Ken Bloom), ( mark4o), (.. SIGIO), , raise() . , , .


, , SIGIO , . , - .

- Linux : - Linux, SIGIO. SIGIO .

, API POSIX AIO, 2.6, , / .

-, - Linux API AIO.

0
source

Source: https://habr.com/ru/post/1739018/


All Articles