- use bb_msg_write_error in 3 places

- whitespace
This commit is contained in:
Bernhard Reutner-Fischer 2006-06-03 20:09:02 +00:00
parent c89982dcd7
commit b1312c9125

View File

@ -1,25 +1,13 @@
/* vi: set sw=4 ts=4: */
/* `time' utility to display resource usage of processes. /* `time' utility to display resource usage of processes.
Copyright (C) 1990, 91, 92, 93, 96 Free Software Foundation, Inc. Copyright (C) 1990, 91, 92, 93, 96 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
it under the terms of the GNU General Public License as published by */
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/* Originally written by David Keppel <pardo@cs.washington.edu>. /* Originally written by David Keppel <pardo@cs.washington.edu>.
Heavily modified by David MacKenzie <djm@gnu.ai.mit.edu>. Heavily modified by David MacKenzie <djm@gnu.ai.mit.edu>.
Heavily modified for busybox by Erik Andersen <andersen@codepoet.org> Heavily modified for busybox by Erik Andersen <andersen@codepoet.org>
*/ */
#include "busybox.h" #include "busybox.h"
#include <stdlib.h> #include <stdlib.h>
@ -38,8 +26,7 @@
#include <sys/resource.h> #include <sys/resource.h>
/* Information on the resources used by a child process. */ /* Information on the resources used by a child process. */
typedef struct typedef struct {
{
int waitstatus; int waitstatus;
struct rusage ru; struct rusage ru;
struct timeval start, elapsed; /* Wallclock time of process. */ struct timeval start, elapsed; /* Wallclock time of process. */
@ -90,15 +77,14 @@ static const char *const long_format =
"\tSocket messages sent: %s\n" "\tSocket messages sent: %s\n"
"\tSocket messages received: %r\n" "\tSocket messages received: %r\n"
"\tSignals delivered: %k\n" "\tSignals delivered: %k\n"
"\tPage size (bytes): %Z\n" "\tPage size (bytes): %Z\n" "\tExit status: %x";
"\tExit status: %x";
/* Wait for and fill in data on child process PID. /* Wait for and fill in data on child process PID.
Return 0 on error, 1 if ok. */ Return 0 on error, 1 if ok. */
/* pid_t is short on BSDI, so don't try to promote it. */ /* pid_t is short on BSDI, so don't try to promote it. */
static int resuse_end (pid_t pid, resource_t *resp) static int resuse_end(pid_t pid, resource_t * resp)
{ {
int status; int status;
@ -106,16 +92,14 @@ static int resuse_end (pid_t pid, resource_t *resp)
/* Ignore signals, but don't ignore the children. When wait3 /* Ignore signals, but don't ignore the children. When wait3
returns the child process, set the time the command finished. */ returns the child process, set the time the command finished. */
while ((caught = wait3 (&status, 0, &resp->ru)) != pid) while ((caught = wait3(&status, 0, &resp->ru)) != pid) {
{
if (caught == -1) if (caught == -1)
return 0; return 0;
} }
gettimeofday (&resp->elapsed, (struct timezone *) 0); gettimeofday(&resp->elapsed, (struct timezone *) 0);
resp->elapsed.tv_sec -= resp->start.tv_sec; resp->elapsed.tv_sec -= resp->start.tv_sec;
if (resp->elapsed.tv_usec < resp->start.tv_usec) if (resp->elapsed.tv_usec < resp->start.tv_usec) {
{
/* Manually carry a one from the seconds field. */ /* Manually carry a one from the seconds field. */
resp->elapsed.tv_usec += 1000000; resp->elapsed.tv_usec += 1000000;
--resp->elapsed.tv_sec; --resp->elapsed.tv_sec;
@ -128,19 +112,18 @@ static int resuse_end (pid_t pid, resource_t *resp)
} }
/* Print ARGV to FP, with each entry in ARGV separated by FILLER. */ /* Print ARGV to FP, with each entry in ARGV separated by FILLER. */
static void fprintargv (FILE *fp, char *const *argv, const char *filler) static void fprintargv(FILE * fp, char *const *argv, const char *filler)
{ {
char *const *av; char *const *av;
av = argv; av = argv;
fputs (*av, fp); fputs(*av, fp);
while (*++av) while (*++av) {
{ fputs(filler, fp);
fputs (filler, fp); fputs(*av, fp);
fputs (*av, fp);
} }
if (ferror (fp)) if (ferror(fp))
bb_error_msg_and_die("write error"); bb_error_msg_and_die(bb_msg_write_error);
} }
/* Return the number of kilobytes corresponding to a number of pages PAGES. /* Return the number of kilobytes corresponding to a number of pages PAGES.
@ -151,7 +134,7 @@ static void fprintargv (FILE *fp, char *const *argv, const char *filler)
Note: Some machines express getrusage statistics in terms of K, Note: Some machines express getrusage statistics in terms of K,
others in terms of pages. */ others in terms of pages. */
static unsigned long ptok (unsigned long pages) static unsigned long ptok(unsigned long pages)
{ {
static unsigned long ps = 0; static unsigned long ps = 0;
unsigned long tmp; unsigned long tmp;
@ -159,16 +142,13 @@ static unsigned long ptok (unsigned long pages)
/* Initialization. */ /* Initialization. */
if (ps == 0) if (ps == 0)
ps = (long) getpagesize (); ps = (long) getpagesize();
/* Conversion. */ /* Conversion. */
if (pages > (LONG_MAX / ps)) if (pages > (LONG_MAX / ps)) { /* Could overflow. */
{ /* Could overflow. */
tmp = pages / 1024; /* Smaller first, */ tmp = pages / 1024; /* Smaller first, */
size = tmp * ps; /* then larger. */ size = tmp * ps; /* then larger. */
} } else { /* Could underflow. */
else
{ /* Could underflow. */
tmp = pages * ps; /* Larger first, */ tmp = pages * ps; /* Larger first, */
size = tmp / 1024; /* then smaller. */ size = tmp / 1024; /* then smaller. */
} }
@ -220,17 +200,21 @@ static unsigned long ptok (unsigned long pages)
COMMAND is the command and args that are being summarized. COMMAND is the command and args that are being summarized.
RESP is resource information on the command. */ RESP is resource information on the command. */
static void summarize (FILE *fp, const char *fmt, char **command, resource_t *resp) static void summarize(FILE * fp, const char *fmt, char **command,
resource_t * resp)
{ {
unsigned long r; /* Elapsed real milliseconds. */ unsigned long r; /* Elapsed real milliseconds. */
unsigned long v; /* Elapsed virtual (CPU) milliseconds. */ unsigned long v; /* Elapsed virtual (CPU) milliseconds. */
if (WIFSTOPPED (resp->waitstatus)) if (WIFSTOPPED(resp->waitstatus))
fprintf (fp, "Command stopped by signal %d\n", WSTOPSIG (resp->waitstatus)); fprintf(fp, "Command stopped by signal %d\n",
else if (WIFSIGNALED (resp->waitstatus)) WSTOPSIG(resp->waitstatus));
fprintf (fp, "Command terminated by signal %d\n", WTERMSIG (resp->waitstatus)); else if (WIFSIGNALED(resp->waitstatus))
else if (WIFEXITED (resp->waitstatus) && WEXITSTATUS (resp->waitstatus)) fprintf(fp, "Command terminated by signal %d\n",
fprintf (fp, "Command exited with non-zero status %d\n", WEXITSTATUS (resp->waitstatus)); WTERMSIG(resp->waitstatus));
else if (WIFEXITED(resp->waitstatus) && WEXITSTATUS(resp->waitstatus))
fprintf(fp, "Command exited with non-zero status %d\n",
WEXITSTATUS(resp->waitstatus));
/* Convert all times to milliseconds. Occasionally, one of these values /* Convert all times to milliseconds. Occasionally, one of these values
comes out as zero. Dividing by zero causes problems, so we first comes out as zero. Dividing by zero causes problems, so we first
@ -242,220 +226,214 @@ static void summarize (FILE *fp, const char *fmt, char **command, resource_t *re
v = resp->ru.ru_utime.tv_sec * 1000 + resp->ru.ru_utime.TV_MSEC + v = resp->ru.ru_utime.tv_sec * 1000 + resp->ru.ru_utime.TV_MSEC +
resp->ru.ru_stime.tv_sec * 1000 + resp->ru.ru_stime.TV_MSEC; resp->ru.ru_stime.tv_sec * 1000 + resp->ru.ru_stime.TV_MSEC;
while (*fmt) while (*fmt) {
{ switch (*fmt) {
switch (*fmt)
{
case '%': case '%':
switch (*++fmt) switch (*++fmt) {
{
case '%': /* Literal '%'. */ case '%': /* Literal '%'. */
putc ('%', fp); putc('%', fp);
break; break;
case 'C': /* The command that got timed. */ case 'C': /* The command that got timed. */
fprintargv (fp, command, " "); fprintargv(fp, command, " ");
break; break;
case 'D': /* Average unshared data size. */ case 'D': /* Average unshared data size. */
fprintf (fp, "%lu", fprintf(fp, "%lu",
MSEC_TO_TICKS (v) == 0 ? 0 : MSEC_TO_TICKS(v) == 0 ? 0 :
ptok ((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS (v) + ptok((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS(v) +
ptok ((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS (v)); ptok((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS(v));
break; break;
case 'E': /* Elapsed real (wall clock) time. */ case 'E': /* Elapsed real (wall clock) time. */
if (resp->elapsed.tv_sec >= 3600) /* One hour -> h:m:s. */ if (resp->elapsed.tv_sec >= 3600) /* One hour -> h:m:s. */
fprintf (fp, "%ldh %ldm %02lds", fprintf(fp, "%ldh %ldm %02lds",
resp->elapsed.tv_sec / 3600, resp->elapsed.tv_sec / 3600,
(resp->elapsed.tv_sec % 3600) / 60, (resp->elapsed.tv_sec % 3600) / 60,
resp->elapsed.tv_sec % 60); resp->elapsed.tv_sec % 60);
else else
fprintf (fp, "%ldm %ld.%02lds", /* -> m:s. */ fprintf(fp, "%ldm %ld.%02lds", /* -> m:s. */
resp->elapsed.tv_sec / 60, resp->elapsed.tv_sec / 60,
resp->elapsed.tv_sec % 60, resp->elapsed.tv_sec % 60,
resp->elapsed.tv_usec / 10000); resp->elapsed.tv_usec / 10000);
break; break;
case 'F': /* Major page faults. */ case 'F': /* Major page faults. */
fprintf (fp, "%ld", resp->ru.ru_majflt); fprintf(fp, "%ld", resp->ru.ru_majflt);
break; break;
case 'I': /* Inputs. */ case 'I': /* Inputs. */
fprintf (fp, "%ld", resp->ru.ru_inblock); fprintf(fp, "%ld", resp->ru.ru_inblock);
break; break;
case 'K': /* Average mem usage == data+stack+text. */ case 'K': /* Average mem usage == data+stack+text. */
fprintf (fp, "%lu", fprintf(fp, "%lu",
MSEC_TO_TICKS (v) == 0 ? 0 : MSEC_TO_TICKS(v) == 0 ? 0 :
ptok ((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS (v) + ptok((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS(v) +
ptok ((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS (v) + ptok((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS(v) +
ptok ((UL) resp->ru.ru_ixrss) / MSEC_TO_TICKS (v)); ptok((UL) resp->ru.ru_ixrss) / MSEC_TO_TICKS(v));
break; break;
case 'M': /* Maximum resident set size. */ case 'M': /* Maximum resident set size. */
fprintf (fp, "%lu", ptok ((UL) resp->ru.ru_maxrss)); fprintf(fp, "%lu", ptok((UL) resp->ru.ru_maxrss));
break; break;
case 'O': /* Outputs. */ case 'O': /* Outputs. */
fprintf (fp, "%ld", resp->ru.ru_oublock); fprintf(fp, "%ld", resp->ru.ru_oublock);
break; break;
case 'P': /* Percent of CPU this job got. */ case 'P': /* Percent of CPU this job got. */
/* % cpu is (total cpu time)/(elapsed time). */ /* % cpu is (total cpu time)/(elapsed time). */
if (r > 0) if (r > 0)
fprintf (fp, "%lu%%", (v * 100 / r)); fprintf(fp, "%lu%%", (v * 100 / r));
else else
fprintf (fp, "?%%"); fprintf(fp, "?%%");
break; break;
case 'R': /* Minor page faults (reclaims). */ case 'R': /* Minor page faults (reclaims). */
fprintf (fp, "%ld", resp->ru.ru_minflt); fprintf(fp, "%ld", resp->ru.ru_minflt);
break; break;
case 'S': /* System time. */ case 'S': /* System time. */
fprintf (fp, "%ld.%02ld", fprintf(fp, "%ld.%02ld",
resp->ru.ru_stime.tv_sec, resp->ru.ru_stime.tv_sec,
resp->ru.ru_stime.TV_MSEC / 10); resp->ru.ru_stime.TV_MSEC / 10);
break; break;
case 'T': /* System time. */ case 'T': /* System time. */
if (resp->ru.ru_stime.tv_sec >= 3600) /* One hour -> h:m:s. */ if (resp->ru.ru_stime.tv_sec >= 3600) /* One hour -> h:m:s. */
fprintf (fp, "%ldh %ldm %02lds", fprintf(fp, "%ldh %ldm %02lds",
resp->ru.ru_stime.tv_sec / 3600, resp->ru.ru_stime.tv_sec / 3600,
(resp->ru.ru_stime.tv_sec % 3600) / 60, (resp->ru.ru_stime.tv_sec % 3600) / 60,
resp->ru.ru_stime.tv_sec % 60); resp->ru.ru_stime.tv_sec % 60);
else else
fprintf (fp, "%ldm %ld.%02lds", /* -> m:s. */ fprintf(fp, "%ldm %ld.%02lds", /* -> m:s. */
resp->ru.ru_stime.tv_sec / 60, resp->ru.ru_stime.tv_sec / 60,
resp->ru.ru_stime.tv_sec % 60, resp->ru.ru_stime.tv_sec % 60,
resp->ru.ru_stime.tv_usec / 10000); resp->ru.ru_stime.tv_usec / 10000);
break; break;
case 'U': /* User time. */ case 'U': /* User time. */
fprintf (fp, "%ld.%02ld", fprintf(fp, "%ld.%02ld",
resp->ru.ru_utime.tv_sec, resp->ru.ru_utime.tv_sec,
resp->ru.ru_utime.TV_MSEC / 10); resp->ru.ru_utime.TV_MSEC / 10);
break; break;
case 'u': /* User time. */ case 'u': /* User time. */
if (resp->ru.ru_utime.tv_sec >= 3600) /* One hour -> h:m:s. */ if (resp->ru.ru_utime.tv_sec >= 3600) /* One hour -> h:m:s. */
fprintf (fp, "%ldh %ldm %02lds", fprintf(fp, "%ldh %ldm %02lds",
resp->ru.ru_utime.tv_sec / 3600, resp->ru.ru_utime.tv_sec / 3600,
(resp->ru.ru_utime.tv_sec % 3600) / 60, (resp->ru.ru_utime.tv_sec % 3600) / 60,
resp->ru.ru_utime.tv_sec % 60); resp->ru.ru_utime.tv_sec % 60);
else else
fprintf (fp, "%ldm %ld.%02lds", /* -> m:s. */ fprintf(fp, "%ldm %ld.%02lds", /* -> m:s. */
resp->ru.ru_utime.tv_sec / 60, resp->ru.ru_utime.tv_sec / 60,
resp->ru.ru_utime.tv_sec % 60, resp->ru.ru_utime.tv_sec % 60,
resp->ru.ru_utime.tv_usec / 10000); resp->ru.ru_utime.tv_usec / 10000);
break; break;
case 'W': /* Times swapped out. */ case 'W': /* Times swapped out. */
fprintf (fp, "%ld", resp->ru.ru_nswap); fprintf(fp, "%ld", resp->ru.ru_nswap);
break; break;
case 'X': /* Average shared text size. */ case 'X': /* Average shared text size. */
fprintf (fp, "%lu", fprintf(fp, "%lu",
MSEC_TO_TICKS (v) == 0 ? 0 : MSEC_TO_TICKS(v) == 0 ? 0 :
ptok ((UL) resp->ru.ru_ixrss) / MSEC_TO_TICKS (v)); ptok((UL) resp->ru.ru_ixrss) / MSEC_TO_TICKS(v));
break; break;
case 'Z': /* Page size. */ case 'Z': /* Page size. */
fprintf (fp, "%d", getpagesize ()); fprintf(fp, "%d", getpagesize());
break; break;
case 'c': /* Involuntary context switches. */ case 'c': /* Involuntary context switches. */
fprintf (fp, "%ld", resp->ru.ru_nivcsw); fprintf(fp, "%ld", resp->ru.ru_nivcsw);
break; break;
case 'e': /* Elapsed real time in seconds. */ case 'e': /* Elapsed real time in seconds. */
fprintf (fp, "%ld.%02ld", fprintf(fp, "%ld.%02ld",
resp->elapsed.tv_sec, resp->elapsed.tv_sec, resp->elapsed.tv_usec / 10000);
resp->elapsed.tv_usec / 10000);
break; break;
case 'k': /* Signals delivered. */ case 'k': /* Signals delivered. */
fprintf (fp, "%ld", resp->ru.ru_nsignals); fprintf(fp, "%ld", resp->ru.ru_nsignals);
break; break;
case 'p': /* Average stack segment. */ case 'p': /* Average stack segment. */
fprintf (fp, "%lu", fprintf(fp, "%lu",
MSEC_TO_TICKS (v) == 0 ? 0 : MSEC_TO_TICKS(v) == 0 ? 0 :
ptok ((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS (v)); ptok((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS(v));
break; break;
case 'r': /* Incoming socket messages received. */ case 'r': /* Incoming socket messages received. */
fprintf (fp, "%ld", resp->ru.ru_msgrcv); fprintf(fp, "%ld", resp->ru.ru_msgrcv);
break; break;
case 's': /* Outgoing socket messages sent. */ case 's': /* Outgoing socket messages sent. */
fprintf (fp, "%ld", resp->ru.ru_msgsnd); fprintf(fp, "%ld", resp->ru.ru_msgsnd);
break; break;
case 't': /* Average resident set size. */ case 't': /* Average resident set size. */
fprintf (fp, "%lu", fprintf(fp, "%lu",
MSEC_TO_TICKS (v) == 0 ? 0 : MSEC_TO_TICKS(v) == 0 ? 0 :
ptok ((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS (v)); ptok((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS(v));
break; break;
case 'w': /* Voluntary context switches. */ case 'w': /* Voluntary context switches. */
fprintf (fp, "%ld", resp->ru.ru_nvcsw); fprintf(fp, "%ld", resp->ru.ru_nvcsw);
break; break;
case 'x': /* Exit status. */ case 'x': /* Exit status. */
fprintf (fp, "%d", WEXITSTATUS (resp->waitstatus)); fprintf(fp, "%d", WEXITSTATUS(resp->waitstatus));
break; break;
case '\0': case '\0':
putc ('?', fp); putc('?', fp);
return; return;
default: default:
putc ('?', fp); putc('?', fp);
putc (*fmt, fp); putc(*fmt, fp);
} }
++fmt; ++fmt;
break; break;
case '\\': /* Format escape. */ case '\\': /* Format escape. */
switch (*++fmt) switch (*++fmt) {
{
case 't': case 't':
putc ('\t', fp); putc('\t', fp);
break; break;
case 'n': case 'n':
putc ('\n', fp); putc('\n', fp);
break; break;
case '\\': case '\\':
putc ('\\', fp); putc('\\', fp);
break; break;
default: default:
putc ('?', fp); putc('?', fp);
putc ('\\', fp); putc('\\', fp);
putc (*fmt, fp); putc(*fmt, fp);
} }
++fmt; ++fmt;
break; break;
default: default:
putc (*fmt++, fp); putc(*fmt++, fp);
} }
if (ferror (fp)) if (ferror(fp))
bb_error_msg_and_die("write error"); bb_error_msg_and_die(bb_msg_write_error);
} }
putc ('\n', fp); putc('\n', fp);
if (ferror (fp)) if (ferror(fp))
bb_error_msg_and_die("write error"); bb_error_msg_and_die(bb_msg_write_error);
} }
/* Run command CMD and return statistics on it. /* Run command CMD and return statistics on it.
Put the statistics in *RESP. */ Put the statistics in *RESP. */
static void run_command (char *const *cmd, resource_t *resp) static void run_command(char *const *cmd, resource_t * resp)
{ {
pid_t pid; /* Pid of child. */ pid_t pid; /* Pid of child. */
__sighandler_t interrupt_signal, quit_signal; __sighandler_t interrupt_signal, quit_signal;
gettimeofday (&resp->start, (struct timezone *) 0); gettimeofday(&resp->start, (struct timezone *) 0);
pid = fork (); /* Run CMD as child process. */ pid = fork(); /* Run CMD as child process. */
if (pid < 0) if (pid < 0)
bb_error_msg_and_die("cannot fork"); bb_error_msg_and_die("cannot fork");
else if (pid == 0) else if (pid == 0) { /* If child. */
{ /* If child. */
/* Don't cast execvp arguments; that causes errors on some systems, /* Don't cast execvp arguments; that causes errors on some systems,
versus merely warnings if the cast is left off. */ versus merely warnings if the cast is left off. */
execvp (cmd[0], cmd); execvp(cmd[0], cmd);
bb_error_msg("cannot run %s", cmd[0]); bb_error_msg("cannot run %s", cmd[0]);
_exit (errno == ENOENT ? 127 : 126); _exit(errno == ENOENT ? 127 : 126);
} }
/* Have signals kill the child but not self (if possible). */ /* Have signals kill the child but not self (if possible). */
interrupt_signal = signal (SIGINT, SIG_IGN); interrupt_signal = signal(SIGINT, SIG_IGN);
quit_signal = signal (SIGQUIT, SIG_IGN); quit_signal = signal(SIGQUIT, SIG_IGN);
if (resuse_end (pid, resp) == 0) if (resuse_end(pid, resp) == 0)
bb_error_msg("error waiting for child process"); bb_error_msg("error waiting for child process");
/* Re-enable signals. */ /* Re-enable signals. */
signal (SIGINT, interrupt_signal); signal(SIGINT, interrupt_signal);
signal (SIGQUIT, quit_signal); signal(SIGQUIT, quit_signal);
} }
int time_main (int argc, char **argv) int time_main(int argc, char **argv)
{ {
int gotone; int gotone;
resource_t res; resource_t res;
@ -467,7 +445,7 @@ int time_main (int argc, char **argv)
* consume the args of our client application... */ * consume the args of our client application... */
while (argc > 0 && **argv == '-') { while (argc > 0 && **argv == '-') {
gotone = 0; gotone = 0;
while (gotone==0 && *++(*argv)) { while (gotone == 0 && *++(*argv)) {
switch (**argv) { switch (**argv) {
case 'v': case 'v':
output_format = long_format; output_format = long_format;
@ -487,15 +465,15 @@ int time_main (int argc, char **argv)
if (argv == NULL || *argv == NULL) if (argv == NULL || *argv == NULL)
bb_show_usage(); bb_show_usage();
run_command (argv, &res); run_command(argv, &res);
summarize (stderr, output_format, argv, &res); summarize(stderr, output_format, argv, &res);
fflush (stderr); fflush(stderr);
if (WIFSTOPPED (res.waitstatus)) if (WIFSTOPPED(res.waitstatus))
exit (WSTOPSIG (res.waitstatus)); exit(WSTOPSIG(res.waitstatus));
else if (WIFSIGNALED (res.waitstatus)) else if (WIFSIGNALED(res.waitstatus))
exit (WTERMSIG (res.waitstatus)); exit(WTERMSIG(res.waitstatus));
else if (WIFEXITED (res.waitstatus)) else if (WIFEXITED(res.waitstatus))
exit (WEXITSTATUS (res.waitstatus)); exit(WEXITSTATUS(res.waitstatus));
return 0; return 0;
} }