diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-02-12 19:31:46 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-02-12 19:31:46 -0500 |
commit | 56c5ca2e6f95ce4ab07bdeffa3e33d6a1aaa2e20 (patch) | |
tree | f60750d67e194212331a190bc828c54fadfeb30b /mstat.c | |
parent | ee0ed5e1087c8e9eea91caea6e82435475c05071 (diff) | |
download | mstat-56c5ca2e6f95ce4ab07bdeffa3e33d6a1aaa2e20.tar.gz |
Do not clear terminal windows while servicing signal(s)
Diffstat (limited to 'mstat.c')
-rw-r--r-- | mstat.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -8,6 +8,7 @@ #ifndef PATH_MAX #define PATH_MAX 4096 #endif +static int enable_cls = 1; struct Option { /** Increased verbosity */ @@ -36,7 +37,7 @@ struct Option { * @param sig the trapped signal */ static void handle_interrupt(int sig) { - printf("SIGNALED %d\n", sig); + enable_cls = 0; switch (sig) { case SIGCHLD: waitpid(option.pid, &option.status, WNOHANG|WUNTRACED); @@ -45,6 +46,7 @@ static void handle_interrupt(int sig) { } else { fprintf(stderr, "warning: pid %d is likely defunct\n", option.pid); } + return; case SIGUSR1: if (option.file) { if (option.verbose) @@ -67,6 +69,7 @@ static void handle_interrupt(int sig) { default: break; } + enable_cls = 1; } static void usage(char *prog) { @@ -150,6 +153,8 @@ int smaps_rollup_usable(pid_t pid) { } static void clearscr() { + if (!enable_cls) + return; printf("\33[H"); printf("\33[2J"); } @@ -280,8 +285,10 @@ int main(int argc, char *argv[]) { clock_gettime(CLOCK_MONOTONIC, &ts_start); // Begin sample loop - printf("PID: %d\nSamples per second: %.2lf\n(interrupt with ctrl-c...)\n", + printf("PID: %d\nSamples per second: %.2lf\n", option.pid, option.sample_rate); + printf("(interrupt with ctrl-c...)\n"); + i = 0; while (1) { if (option.verbose && isatty(STDOUT_FILENO)) { @@ -317,6 +324,7 @@ int main(int argc, char *argv[]) { x++; } puts("\n"); + printf("(interrupt with ctrl-c...)\n"); } if (mstat_write(option.file, &record) < 0) { |