Вопрос

I have two progress, p1 and p2, and a named pipe var for ipc between 2 progress.
I want to lock var's rw for p2 when p1 writes, and unlock var when p1 finished write.

ps:

I using select for nonblocking, so p2 will get readable when p1 put anything to var.Can I let var become readable when p1 finish write?

Это было полезно?

Решение

You could use signals (e.g. SIGUSR1). The writer makes it pipe non-blocking (so it won't block when the pipe becomes full), writes until it can't write anymore, then send the signal to the other process. The reading process reads all (from its non-blocking pipe), then sends a signal to the writer who then continues to write.

However, this is really not needed. The writer can just write, and the reader just read. If the pipe becomes full the writer will block until it can write more. And the same for the reader, it will block if there's nothing to read. Then when the writer has written all data, it will simply close its end of the pipe, which the reader will detect with a read call that returns zero bytes read.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top