From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sun, 2 Nov 2008 21:48:10 -0800 From: Roman Shaposhnik To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Message-id: <3B877C19-C5A8-4C76-BF24-D2A793E7BFC1@sun.com> MIME-version: 1.0 Content-type: multipart/alternative; boundary="Boundary_(ID_Ay6Rx+jMTAjnVL7SYFMMiA)" Subject: [9fans] Questions on notes Topicbox-Message-UUID: 2d44233e-ead4-11e9-9d60-3106f5b1d025 --Boundary_(ID_Ay6Rx+jMTAjnVL7SYFMMiA) Content-type: text/plain; delsp=yes; format=flowed; charset=US-ASCII Content-transfer-encoding: 7BIT 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 #include 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 --Boundary_(ID_Ay6Rx+jMTAjnVL7SYFMMiA) Content-type: text/html; charset=US-ASCII Content-transfer-encoding: QUOTED-PRINTABLE 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 you= r help.

First of all, the proc(3) man page s= ays that "A read [from /proc/n/note] of at least ERRLEN
cha= racters will retrieve the oldest note posted to the process and pr= event its delivery to
the process" and= for some reason I have always assumed that the read would be a block= ing
one. Yet, it doesn't seem to be the case:
&nb= sp;   term% dd -if /proc/1/note -bs 256
 &nb= sp;  0+0 record in
    0+0 records out<= /div>
A visit to /sys/src/9/port/devproc.c confirms that if = there are no notes any read immediately
return with 0. At t= his point the whole idea of letting an external process read notes su= ddenly
becomes much less appealing: the only option left to= the reader is constant polling(*). On
top of that the= re always seems to be a race condition between somebody reading on /p= roc/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 fo= r 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>

<= div>void door_bell(void* dummy, char* note)
{
&nb= sp;   print("look who's there: %s\n", note);
&nbs= p;   noted(NCONT);
}

int= main()
{
   char buf[256];
&= nbsp;  int fd,i;

   sprint(bu= f, "/proc/%d/note", getpid());
   fd =3D open(buf= , OREAD);
   notify(door_bell);
 &= nbsp; print("starting up: %d\n", fd);
   for (;;)= {
      if ((i =3D read(fd, buf, sizeo= f(buf))) < 0)
          br= eak;
      if (i)
  = ;        print("selfserving: %s\n", buf);
   }
   return 0;
}
<= div>
term%  8c test.c ; 8l test.8 ; ./8.out
<= div>
EVERYTHING IS DEAD AT THIS POINT
--Boundary_(ID_Ay6Rx+jMTAjnVL7SYFMMiA)--