2018-08-04 22:06:27 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2018-08-05 10:24:01 +00:00
|
|
|
use Config;
|
2018-08-04 22:06:27 +00:00
|
|
|
|
|
|
|
if (@ARGV < 2) {
|
|
|
|
die "Usage: $0 <prefix> <command...>\n";
|
|
|
|
}
|
|
|
|
|
2018-08-05 10:24:01 +00:00
|
|
|
sub gettime {
|
|
|
|
my ($sec, $usec);
|
|
|
|
|
|
|
|
eval {
|
|
|
|
require Time::HiRes;
|
|
|
|
($sec, $usec) = Time::HiRes::gettimeofday();
|
|
|
|
};
|
|
|
|
|
|
|
|
unless (defined($sec) && defined($usec)) {
|
|
|
|
my $tv_t = ($Config{'longsize'} == 8) ? 'qq' : 'll';
|
|
|
|
my $tv = pack $tv_t, 0, 0;
|
|
|
|
|
|
|
|
eval {
|
|
|
|
require 'syscall.ph';
|
|
|
|
syscall(SYS_gettimeofday(), $tv, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
($sec, $usec) = unpack $tv_t, $tv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ($sec, $usec);
|
|
|
|
}
|
|
|
|
|
2018-08-04 22:06:27 +00:00
|
|
|
my ($prefix, @cmd) = @ARGV;
|
2018-08-05 10:24:01 +00:00
|
|
|
my ($sec, $usec) = gettime();
|
2018-08-04 22:06:27 +00:00
|
|
|
my $pid = fork();
|
|
|
|
|
|
|
|
if (!defined($pid)) {
|
|
|
|
die "$0: Failure to fork(): $!\n";
|
|
|
|
}
|
|
|
|
elsif ($pid == 0) {
|
|
|
|
exec(@cmd);
|
|
|
|
die "$0: Failure to exec(): $!\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$SIG{'INT'} = 'IGNORE';
|
|
|
|
$SIG{'QUIT'} = 'IGNORE';
|
|
|
|
|
|
|
|
if (waitpid($pid, 0) == -1) {
|
|
|
|
die "$0: Failure to waitpid(): $!\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $exitcode = $? >> 8;
|
2018-08-05 10:24:01 +00:00
|
|
|
my ($sec2, $usec2) = gettime();
|
2018-08-04 22:06:27 +00:00
|
|
|
my (undef, undef, $cuser, $csystem) = times();
|
|
|
|
|
|
|
|
printf STDERR "%s#%.2f#%.2f#%.2f\n",
|
|
|
|
$prefix, $cuser, $csystem,
|
2018-08-05 10:24:01 +00:00
|
|
|
($sec2 - $sec) + ($usec2 - $usec) / 1000000;
|
2018-08-04 22:06:27 +00:00
|
|
|
|
|
|
|
$SIG{'INT'} = 'DEFAULT';
|
|
|
|
$SIG{'QUIT'} = 'DEFAULT';
|
|
|
|
|
|
|
|
exit $exitcode;
|
|
|
|
}
|