From 603499b6740839c2b3b6123f784a1237e6451074 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 8 Mar 2015 12:49:24 +0100 Subject: [PATCH] time: show which signal terminated the program, exit status The exit status when a program is signaled is not specified in POSIX afaik. The GNU behaviour of 128 + signalno is used. --- time.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/time.c b/time.c index fc17bf0..0b8e607 100644 --- a/time.c +++ b/time.c @@ -21,7 +21,7 @@ main(int argc, char *argv[]) struct tms tms; /* user and sys times */ clock_t r0, r1; /* real time */ long ticks; /* per second */ - int status, savederrno; + int status, savederrno, ret = 0; ARGBEGIN { case 'p': @@ -55,10 +55,19 @@ main(int argc, char *argv[]) if ((r1 = times(&tms)) < 0) eprintf("times:"); + if (WIFSIGNALED(status)) { + fprintf(stderr, "Command terminated by signal %d\n", + WTERMSIG(status)); + ret = 128 + WTERMSIG(status); + } + fprintf(stderr, "real %f\nuser %f\nsys %f\n", (r1 - r0) / (double)ticks, tms.tms_cutime / (double)ticks, tms.tms_cstime / (double)ticks); - return WIFEXITED(status) ? WEXITSTATUS(status) : 0; + if (WIFEXITED(status)) + ret = WEXITSTATUS(status); + + return ret; }