When a process is monitored with option -e, pidstat should return the
exit code of this process and a default value of 0.
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
#include <sys/types.h>
#include <pwd.h>
#include <sys/utsname.h>
+#include <sys/wait.h>
#include <regex.h>
#ifdef HAVE_LINUX_SCHED_H
struct sigaction alrm_act, int_act, chld_act;
int signal_caught = 0;
+int status = 0;
int dplaces_nr = -1; /* Number of decimal places */
*/
void int_handler(int sig)
{
- signal_caught = 1;
+ int status_code;
+
+ signal_caught = TRUE;
+
+ if (sig == SIGCHLD) {
+ /*
+ * SIGCHLD tells the parent process that it can now
+ * get the exit status of the child via wait().
+ */
+ wait(&status_code);
+ status = WEXITSTATUS(status_code);
+ }
}
/*
/* Free structures */
sfree_pid(&pid_list, TRUE);
- return 0;
+ /*
+ * @status contains the exit code of the child process monitored with option -e,
+ * or 0 otherwise.
+ */
+ return status;
}