From owner-freebsd-hackers Mon Sep 18 11:36:38 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from bingnet2.cc.binghamton.edu (bingnet2.cc.binghamton.edu [128.226.1.18]) by hub.freebsd.org (Postfix) with ESMTP id C87E437B423 for ; Mon, 18 Sep 2000 11:36:30 -0700 (PDT) Received: from jade (jade.cs.binghamton.edu [128.226.140.161]) by bingnet2.cc.binghamton.edu (8.9.3/8.9.3) with ESMTP id OAA22570 for ; Mon, 18 Sep 2000 14:36:27 -0400 (EDT) Date: Mon, 18 Sep 2000 14:36:08 -0400 (EDT) From: Zhiui Zhang X-Sender: zzhang@jade To: freebsd-hackers@freebsd.org Subject: How to time a system call Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG A friend asks me what will happen if more than one process trying to read the stdin at the same time. There is no way to guarantee that any particular keyboard input will be accepted by a particular process. Since a system call is atomic, this makes me wonder how long it takes to do a system call, like read(), on a 500Mhz PC? How to time it? I later write a program that forks. So that two processes tries to read the stdin at the same time. I use read() to read one character at a time. Each process read 1000 characters and write what they read to a file. I use I/O redirect to let them read from the same file instead of keyboard. I find out that one process always call 1000 read()s before the second has a chance to call read(). I hope someone can give me a clue on how this is happening. Maybe the scheduling quantum (100ms?) is just enough for doing 1000 read() system calls. Is there any easy way to time a system call (perhaps with minor modifications of the kernel)? Any help is appreciated. -Zhihui To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message