From 5562fd2485bfd04014e3ad841033af987c96f090 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Fri, 20 Sep 2013 15:09:25 +0200 Subject: [PATCH] mpstat/pidstat exit immediately when SIGINT caught during 1st interval The mpstat and pidstat commands display their average statistics when they are interrupted by the user with control-C (SIGINT signal). But when the signal was caught during the first interval of time (ie. before any statistics had been displayed), trying to display some average values is irrelevant. So make them exit immediately in this case. --- mpstat.c | 4 ++++ pidstat.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/mpstat.c b/mpstat.c index 1521755..e67838e 100644 --- a/mpstat.c +++ b/mpstat.c @@ -798,6 +798,10 @@ void rw_mpstat_loop(int dis_hdr, int rows) sigaction(SIGINT, &int_act, NULL); pause(); + + if (sigint_caught) + /* SIGINT signal caught during first interval: Exit immediately */ + return; do { /* diff --git a/pidstat.c b/pidstat.c index be82a25..192460f 100644 --- a/pidstat.c +++ b/pidstat.c @@ -1948,6 +1948,10 @@ void rw_pidstat_loop(int dis_hdr, int rows) /* Wait for SIGALRM (or possibly SIGINT) signal */ pause(); + if (sigint_caught) + /* SIGINT signal caught during first interval: Exit immediately */ + return; + do { /* Get time */ get_localtime(&ps_tstamp[curr], 0); -- 2.40.0