From: Bob Peterson Date: Fri, 26 Feb 2016 14:57:53 -0500 (EST) Subject: [Cluster-devel] [PATCH] glocktop: Fix a tight loop under nohup In-Reply-To: <1456444269-31101-1-git-send-email-anprice@redhat.com> References: <1456444269-31101-1-git-send-email-anprice@redhat.com> Message-ID: <1897847453.31147938.1456516673407.JavaMail.zimbra@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit ----- Original Message ----- > When glocktop is run under nohup, it redirects /dev/null to stdin, which > flags up EOF and causes the file descriptor to always be in a ready > state when select()ed. This causes select() to return immediately > instead of timing out after the refresh delay. > > Make sure to sleep for the refresh delay on EOF to avoid getting into a > tight loop when running under nohup. > > Signed-off-by: Andrew Price > --- > gfs2/glocktop/glocktop.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/gfs2/glocktop/glocktop.c b/gfs2/glocktop/glocktop.c > index 43c3c3f..fe6bcc2 100644 > --- a/gfs2/glocktop/glocktop.c > +++ b/gfs2/glocktop/glocktop.c > @@ -1856,6 +1856,15 @@ int main(int argc, char **argv) > if (refresh_time < 1) > refresh_time = 1; > break; > + /* We can get an EOF if the user hits ^D or if > + /dev/null is redirected to stdin, such as when > + running under nohup. It should be safe to assume the > + latter since ^D shouldn't be expected to do anything > + useful. In that case, select() returns immediately > + so we need to enforce the refresh delay with a sleep */ > + case EOF: > + sleep(refresh_time); > + break; > } > } > iters_done++; > -- > 2.4.3 > > ACK Bob Peterson