9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Anthony Martin <ality@pbrane.org>
To: 9fans <9fans@9fans.net>
Subject: [9fans] Re: Pipes staying after sending note
Date: Sat, 8 Jul 2023 17:03:59 -0700	[thread overview]
Message-ID: <ZKn5b4s7yTJONYTD@alice> (raw)
In-Reply-To: <abToz2TrFbB_rDZLToX8KYmdmHCsdFYT4ZADL09J-GIQHz_IwpO_zPS65WI0SAxidGFcDtMn0_wHe3a7Bq3rbugbMz5SKyjXyxCMAOOr9t0=@protonmail.com>

Philip Silva via 9fans <9fans@9fans.net> once said:
>         if ((cpid = fork()) != 0) {
>                 close(infd[1]);
>                 close(outfd[1]);
>
>                 n = write(infd[0], "test", 4);
>                 printf("check process: wrote %d bytes\n", n);
>
>                 sendnote(cpid);
>                 // close(infd[0]);  // <--- uncomment to make write fail
>                 // close(outfd[0]);
>
>                 n = write(infd[0], "test2", 5);
>                 printf("write: wrote %d bytes\n", n);
>
>                 n = read(outfd[0], outbuf, 20);
>                 printf("outbuf=%s (n=%d)\n", outbuf, n);
>                 wait();
>                 return 0;

Why aren't you waiting for the process to die
after sending it the note? It must be running
to see that is has a note pending. At the time
of your second write, the scheduler may not
have selected the child process to run.

The sequence could look like:

child: read from empty pipe, go to sleep
parent: write to pipe
parent: write kill to /proc/$cpid/note
parent: write to pipe
child: wakeup, see note, die

Cheers,
  Anthony

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T3392001a02ee7ec8-Mfe03d0d140063db1ea509f2a
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

      reply	other threads:[~2023-07-09  0:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-08 15:46 [9fans] " Philip Silva via 9fans
2023-07-09  0:03 ` Anthony Martin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZKn5b4s7yTJONYTD@alice \
    --to=ality@pbrane.org \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).