From: Oleg Nesterov <oleg@redhat.com>
To: "Andrew Morton" <akpm@linux-foundation.org>,
"Lluís Batlle i Rossell" <viric@viric.name>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Hang opening a pipe written to by a child, with SIGCHLD
Date: Wed, 11 Apr 2012 00:55:16 +0200 [thread overview]
Message-ID: <20120410225516.GA13486@redhat.com> (raw)
In-Reply-To: <20120409120326.f0ce7a94.akpm@linux-foundation.org>
On 04/09, Andrew Morton wrote:
>
> Begin forwarded message:
>
> Date: Mon, 2 Apr 2012 16:46:11 +0200
> From: Lluís Batlle i Rossell <viric@viric.name>
> To: linux-kernel@vger.kernel.org
> Subject: Hang opening a pipe written to by a child, with SIGCHLD
>
>
> Hello,
>
> I had troubles running a simple bash script where a child wrote to a named pipe
> before dying, and the parent opened and read the pipe.
>
> On a computer, my script hangs always. Also under 'strace'. Not under 'strace
> -f'. Thinking of some race, I wrote a small script that hangs in the linuxes I
> could try (3.2.11 now):
>
> ----------
> #!/var/run/current-system/sw/bin/bash
>
> PIPE=/tmp/pipe
>
> rm -f $PIPE
> mkfifo $PIPE
>
> function spawn {
> echo DONE > $PIPE
> }
>
> spawn sleep 1 &
>
> while true; do
> echo reading
> while read LINE < $PIPE; do
> echo $LINE
> spawn &
> done
> done
Looks like, it hangs "correctly". At least from the kernel pov.
The parent sleeps in fifo_open()->wait_for_partner(), but there
are no pipe->writers.
Note that the parent (bash) re-opens /tmp/pipe after every "spawn".
Now,
- the parent (bash) forks the new child
- the new child sleeps waiting for reader
- the parent does open(pipe), this wakes up the child
- the child opens the pipe, writes, and exits
- the open from the child wakes up the parent, but
since it exits quickly fifo_open(FMODE_READ) can
notice the pending SIGCHLD and return -EINTR
- the parent restarts sys_open(), but nobody can
open it for writing
May be you can ask bash developers. Perhaps bash can move the
"restore stdin" logic into the child process, I dunno.
Or may be you can "fix" this script, just add "exec < $PIPE"
before the main "while true" loop.
Oleg.
next parent reply other threads:[~2012-04-10 22:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20120409120326.f0ce7a94.akpm@linux-foundation.org>
2012-04-10 22:55 ` Oleg Nesterov [this message]
2012-04-10 23:12 ` Hang opening a pipe written to by a child, with SIGCHLD Oleg Nesterov
2012-04-02 14:46 Lluís Batlle i Rossell
2012-04-02 14:49 ` Shea Levy
2012-04-02 18:50 ` Lluís Batlle i Rossell
2012-04-02 20:20 ` Lluís Batlle i Rossell
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=20120410225516.GA13486@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viric@viric.name \
/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).