From: Zoltan Hidvegi <hzoli@cs.elte.hu>
To: hoh@approve.se (Goran Larsson)
Cc: zsh-workers@math.gatech.edu
Subject: Re: time builtin
Date: Mon, 27 Jan 1997 23:02:25 +0100 (MET) [thread overview]
Message-ID: <199701272202.XAA13587@bolyai.cs.elte.hu> (raw)
In-Reply-To: <m0voxzo-000X3aC@lorelei.approve.se> from Goran Larsson at "Jan 27, 97 09:49:40 pm"
Goran Larsson wrote:
> Now printtime() in 2.6-beta13 had this code:
>
> if (percent > 100)
> percent = 100; /* just to make it look right */
>
> but that was removed in 3.0.0. Reinserting those two lines
> in 3.0.0 obviously ``fixes'' the problem, or perhaps it is
> more accurate to say that it hides the real problem again.
>
> Is it possible to fix this, or are the times here just to
> close to the resolution provided by the kernel?
Perhaps. Or it may be a kernel bug. Solaris has one. Try the program
below. It prints three time lines, and the last two shoud be the same.
That's not the case on Solaris.
What happens:
A forks B, B forks C and exits. C consumes CPU time then exits. This is
accounted for A but A does not receive the child signal when C dies so it
siply accounts this time to its next child.
Zoltan
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/times.h>
#include <stdio.h>
void
printsig(int signum)
{
printf("Received signal %d\n", signum);
}
void
install_handler(int sig, void (*handler)(int))
{
struct sigaction act;
act.sa_handler = handler;
sigemptyset(&act.sa_mask); /* only block sig while in handler */
act.sa_flags = 0;
sigaction(sig, &act, (struct sigaction *)NULL);
}
int
main(int argc, char *argv[])
{
pid_t ppid = getpid();
pid_t pid, wpid;
int status;
struct tms tms;
double clktck = sysconf(_SC_CLK_TCK);
pid = fork();
if (pid < 0) {
perror(argv[0]);
exit(1);
} else if (!pid) {
int i;
if (fork())
exit(0);
for (i = 100000000; i--;);
kill(ppid, SIGUSR1);
exit(1);
}
install_handler(SIGUSR1, printsig);
install_handler(SIGCHLD, printsig);
while ((wpid = wait(&status)) == -1)
perror(argv[0]);
if (wpid != pid) {
fprintf(stderr, "%s: unknown child: %d instead of %d.\n",
argv[0], (int) wpid, (int) pid);
exit(1);
}
times(&tms);
printf("%.2fs system, %.2fs user\n",
tms.tms_cstime / clktck, tms.tms_cutime / clktck);
pause();
times(&tms);
printf("%.2fs system, %.2fs user\n",
tms.tms_cstime / clktck, tms.tms_cutime / clktck);
sleep(2);
times(&tms);
printf("%.2fs system, %.2fs user\n",
tms.tms_cstime / clktck, tms.tms_cutime / clktck);
exit(0);
}
prev parent reply other threads:[~1997-01-27 22:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-01-27 20:49 Goran Larsson
1997-01-27 22:02 ` Zoltan Hidvegi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199701272202.XAA13587@bolyai.cs.elte.hu \
--to=hzoli@cs.elte.hu \
--cc=hoh@approve.se \
--cc=zsh-workers@math.gatech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).