9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Questions on notes
@ 2008-11-03  5:48 Roman Shaposhnik
  2008-11-03 13:03 ` erik quanstrom
  0 siblings, 1 reply; 11+ messages in thread
From: Roman Shaposhnik @ 2008-11-03  5:48 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 1853 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 3026 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [9fans] Questions on notes
@ 2008-11-03 18:26 erik quanstrom
  0 siblings, 0 replies; 11+ messages in thread
From: erik quanstrom @ 2008-11-03 18:26 UTC (permalink / raw)
  To: blstuart, 9fans

> > Frankly, I was trying to see whether an external process reading
> > on somebody else's /proc/n/note would make any sense. One thing
> > that I wanted to implement was a "note thief" process that would
> > constantly read on a target's /proc/n/note and handle the notes
> > externally using a different kind of IPC to communicate with
> > the target. Am I dreaming? Would this be completely impossible
> > to implement using /proc/n/note ?
>
> If proc n needs to know about this design, then could
> you just always direct the notes to the "thief?"  Or
> if the thief were a little file server, could you bind
> the file he listens to on top of /proc/n/note?

the kernel would not notice this binding.

- erik



^ permalink raw reply	[flat|nested] 11+ messages in thread
[parent not found: <42d8f7e804069264141e6e4f33b8baf9@quanstro.net>]

end of thread, other threads:[~2008-11-06  5:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-03  5:48 [9fans] Questions on notes Roman Shaposhnik
2008-11-03 13:03 ` erik quanstrom
2008-11-03 16:46   ` Roman V. Shaposhnik
2008-11-03 17:05     ` Brian L. Stuart
2008-11-03 17:41     ` dave.l
2008-11-05  5:05       ` Roman Shaposhnik
2008-11-05  5:16         ` ron minnich
2008-11-06  5:09           ` Roman Shaposhnik
2008-11-03 18:26 erik quanstrom
     [not found] <42d8f7e804069264141e6e4f33b8baf9@quanstro.net>
2008-11-03 18:48 ` Brian L. Stuart
2008-11-05  2:02   ` Roman V. Shaposhnik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).