From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/pipe13: Add regression test for pipe to wake up all readers
Date: Tue, 25 Feb 2020 11:28:50 +0100 [thread overview]
Message-ID: <20200225102850.GA5077@rei.lan> (raw)
In-Reply-To: <0bfca454-8c44-6435-81fb-a243172ef96f@cn.fujitsu.com>
Hi!
> > We should just use waitpid with -1 as a pid here and WNOHANG twice,
> > because if one of the children hangs it's not guaranteed in any way
> > which one would that be.
> >
> On my environment, kernel wakes up the first read and the remaining read
> doesn't be waked up. (I add three childs, 2,3 doesn't wake up)
But that behavior is not written down in any standard, that's just how
the kernel internals are working at the moment, we should not assume it
will work like this in the future.
What I would do here would be:
int ret, cnt = 0, sleep_us = 1, fail = 0;
while (cnt < 2 && sleep_us < 100000) {
ret = waitpid(-1, NULL, WNOHANG);
if (ret < 0)
tst_brk(TBROK | TERRNO, "waitpid()");
if (ret > 0) {
cnt++;
for (i = 0; i < 2; i++) {
if (pid[i] == ret)
pid[i] = 0;
}
continue;
}
usleep(sleep_time);
sleep_time *= 2;
}
for (i = 0; i < 2; i++) {
if (pid[i]) {
tst_res(TINFO, "pid %i still sleeps", pid[i]);
fail = 1;
SAFE_KILL(pid[i], SIGKILL);
SAFE_WAIT(NULL);
}
}
if (fail)
tst_res(TFAIL, "Closed pipe didn't wake everyone");
This has also advantage that we can easily run the test even for 100
children as well as two if we change the upper bound of the for loops to
a variable.
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2020-02-25 10:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 9:52 [LTP] [PATCH] syscalls/pipe13: Add regression test for pipe to wake up all readers Yang Xu
2020-02-24 12:58 ` Cyril Hrubis
2020-02-25 9:07 ` Yang Xu
2020-02-25 10:28 ` Cyril Hrubis [this message]
2020-02-26 1:27 ` Yang Xu
2020-02-26 3:06 ` [LTP] [PATCH v3] " Yang Xu
2020-02-26 13:56 ` Cyril Hrubis
2020-02-25 9:57 ` [LTP] [PATCH v2] " Yang Xu
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=20200225102850.GA5077@rei.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/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