]> granicus.if.org Git - sysstat/commitdiff
pidstat: Monitor and show stats at the end of the exec program
authorParth Shah <parths1229@gmail.com>
Wed, 31 Mar 2021 11:59:06 +0000 (17:29 +0530)
committerParth Shah <parths1229@gmail.com>
Wed, 31 Mar 2021 12:03:18 +0000 (17:33 +0530)
Do not set alarms for undefined value of the interval. Also allow to
print stats even if the SIGINT/SIGCHLD occurs before first interval.
Hence, the command `pidstat -e <prog-name>`
will monitor the prog-name process and show the PID stats after the
prog-name is completed its execution.

Signed-off-by: Parth Shah <parths1229@gmail.com>
pidstat.c

index 076e6640b7b10d6e1425d278858887749eea54fa..0f827f83554d56c03c40c42f1051c536b161a95e 100644 (file)
--- a/pidstat.c
+++ b/pidstat.c
@@ -2366,15 +2366,14 @@ void rw_pidstat_loop(int dis_hdr, int rows)
        if (!interval) {
                /* Display since boot time */
                ps_tstamp[1] = ps_tstamp[0];
-               write_stats(0, DISP_HDR);
-               exit(0);
        }
 
        /* Set a handler for SIGALRM */
        memset(&alrm_act, 0, sizeof(alrm_act));
        alrm_act.sa_handler = alarm_handler;
        sigaction(SIGALRM, &alrm_act, NULL);
-       alarm(interval);
+       if (interval)
+               alarm(interval);
 
        /* Save the first stats collected. Will be used to compute the average */
        ps_tstamp[2] = ps_tstamp[0];
@@ -2392,7 +2391,7 @@ void rw_pidstat_loop(int dis_hdr, int rows)
        /* Wait for SIGALRM (or possibly SIGINT) signal */
        __pause();
 
-       if (signal_caught)
+       if (signal_caught && interval)
                /* SIGINT/SIGCHLD signals caught during first interval: Exit immediately */
                return;