Guys,
I've been experimenting with how Plan 9 handles notes for processes and
I must confess that I'm now confused and in need your help.
First of all, the proc(3) man page says that "A read [from /proc/n/
note] of at least ERRLEN
characters will retrieve the oldest note posted to the process and
prevent its delivery to
the process" and for some reason I have always assumed that the read
would be a blocking
one. Yet, it doesn't seem to be the case:
term% dd -if /proc/1/note -bs 256
0+0 record in
0+0 records out
A visit to /sys/src/9/port/devproc.c confirms that if there are no
notes any read immediately
return with 0. At this point the whole idea of letting an external
process read notes suddenly
becomes much less appealing: the only option left to the reader is
constant polling(*). On
top of that there always seems to be a race condition between somebody
reading on /proc/n/note
and the scheduler actually delivering a note via the call to a
handler. These two things
make me the following question: what is the point of reading /proc/n/
note for anything but a
stopped/borken process?
Thanks,
Roman.
(*) Speaking of constant polling: the following hangs 9vx for good on
my system:
term% cat test.c
#include <u.h>
#include <libc.h>
void door_bell(void* dummy, char* note)
{
print("look who's there: %s\n", note);
noted(NCONT);
}
int main()
{
char buf[256];
int fd,i;
sprint(buf, "/proc/%d/note", getpid());
fd = open(buf, OREAD);
notify(door_bell);
print("starting up: %d\n", fd);
for (;;) {
if ((i = read(fd, buf, sizeof(buf))) < 0)
break;
if (i)
print("selfserving: %s\n", buf);
}
return 0;
}
term% 8c test.c ; 8l test.8 ; ./8.out
EVERYTHING IS DEAD AT THIS POINT