SIGINT (crtl/c).
mpstat and sar/sadc now catch SIGINT (ctrl/c) and display their average
statistics when received.
xxxx/xx/xx: Version 10.1.4 - Sebastien Godard (sysstat <at> orange.fr)
* [Christophe Cerin]: pidstat now stops and displays its average
stats when it receives SIGINT (crtl/c).
+ * mpstat now stops and displays its average stats when it
+ receives SIGINT (crtl/c).
+ * sar now stops and displays its average stats when it receives
+ SIGINT (crtl/c).
2012/12/23: Version 10.1.3 - Sebastien Godard (sysstat <at> orange.fr)
* Changed network counters (used by sar -n {DEV | EDEV }) to
/*
* mpstat: per-processor statistics
- * (C) 2000-2012 by Sebastien GODARD (sysstat <at> orange.fr)
+ * (C) 2000-2013 by Sebastien GODARD (sysstat <at> orange.fr)
*
***************************************************************************
* This program is free software; you can redistribute it and/or modify it *
/* Nb of soft interrupts per processor */
int softirqcpu_nr = 0;
+int sigint_caught = 0;
+
/*
***************************************************************************
* Print usage and exit
* SIGALRM signal handler
*
* IN:
- * @sig Signal number. Set to 0 for the first time, then to SIGALRM.
+ * @sig Signal number.
***************************************************************************
*/
void alarm_handler(int sig)
alarm(interval);
}
+/*
+ ***************************************************************************
+ * SIGINT signal handler.
+ *
+ * IN:
+ * @sig Signal number.
+ ***************************************************************************
+ */
+void int_handler(int sig)
+{
+ sigint_caught = 1;
+}
+
/*
***************************************************************************
* Allocate stats structures and cpu bitmap.
STATS_IRQCPU_SIZE * (cpu_nr + 1) * softirqcpu_nr);
}
+ /* Set a handler for SIGINT */
+ signal(SIGINT, int_handler);
+
pause();
do {
if (count > 0) {
count--;
}
+
if (count) {
- curr ^= 1;
+
pause();
+
+ if (sigint_caught) {
+ /* SIGINT signal caught => Display average stats */
+ count = 0;
+ printf("\n"); /* Skip "^C" displayed on screen */
+ }
+ else {
+ curr ^= 1;
+ }
}
}
while (count);
* SIGALRM signal handler.
*
* IN:
- * @sig Signal number. Set to 0 for the first time, then to SIGALRM.
+ * @sig Signal number.
***************************************************************************
*/
void alarm_handler(int sig)
if (count) {
pause();
-
+
if (sigint_caught) {
/* SIGINT signal caught => Display average stats */
count = 0;
/*
* sadc: system activity data collector
- * (C) 1999-2012 by Sebastien GODARD (sysstat <at> orange.fr)
+ * (C) 1999-2013 by Sebastien GODARD (sysstat <at> orange.fr)
*
***************************************************************************
* This program is free software; you can redistribute it and/or modify it *
unsigned int flags = 0;
int dis;
+int optz = 0;
char timestamp[2][TIMESTAMP_LEN];
struct file_header file_hdr;
* SIGALRM signal handler.
*
* IN:
- * @sig Signal number. Set to 0 for the first time, then to SIGALRM.
+ * @sig Signal number.
***************************************************************************
*/
void alarm_handler(int sig)
alarm(interval);
}
+/*
+ ***************************************************************************
+ * SIGINT signal handler.
+ *
+ * IN:
+ * @sig Signal number.
+ ***************************************************************************
+ */
+void int_handler(int sig)
+{
+ if (!optz) {
+ /* sadc hasn't been called by sar */
+ exit(1);
+ }
+
+ /*
+ * When starting sar then pressing ctrl/c, SIGINT is received
+ * by sadc, not sar. So send SIGINT to sar so that average stats
+ * can be displayed.
+ */
+ if (kill(getppid(), SIGINT) < 0) {
+ exit(1);
+ }
+}
+
/*
***************************************************************************
* Display an error message.
char new_ofile[MAX_FILE_LEN];
new_ofile[0] = '\0';
+
+ /* Set a handler for SIGINT */
+ signal(SIGINT, int_handler);
/* Main loop */
do {
*/
int main(int argc, char **argv)
{
- int opt = 0, optz = 0;
+ int opt = 0;
char ofile[MAX_FILE_LEN];
struct tm rectime;
int stdfd = 0, ofd = -1;
/*
* sar: report system activity
- * (C) 1999-2012 by Sebastien GODARD (sysstat <at> orange.fr)
+ * (C) 1999-2013 by Sebastien GODARD (sysstat <at> orange.fr)
*
***************************************************************************
* This program is free software; you can redistribute it and/or modify it *
#include <unistd.h>
#include <time.h>
#include <errno.h>
+#include <signal.h>
#include "version.h"
#include "sa.h"
extern struct activity *act[];
+int sigint_caught = 0;
+
/*
***************************************************************************
* Print usage title message.
exit(0);
}
+/*
+ ***************************************************************************
+ * SIGINT signal handler.
+ *
+ * IN:
+ * @sig Signal number.
+ ***************************************************************************
+ */
+void int_handler(int sig)
+{
+ sigint_caught = 1;
+ printf("\n"); /* Skip "^C" displayed on screen */
+
+}
+
/*
***************************************************************************
* Init some structures.
/* Save the first stats collected. Will be used to compute the average */
copy_structures(act, id_seq, record_hdr, 2, 0);
+ /* Set a handler for SIGINT */
+ signal(SIGINT, int_handler);
+
/* Main loop */
do {
count--;
}
if (count) {
- curr ^= 1;
+ if (sigint_caught) {
+ /* SIGINT signal caught => Display average stats */
+ count = 0;
+ }
+ else {
+ curr ^= 1;
+ }
}
}
while (count);