From owner-freebsd-questions Mon Jan 17 6:41: 7 2000 Delivered-To: freebsd-questions@freebsd.org Received: from merkur.hrz.uni-giessen.de (merkur.hrz.uni-giessen.de [134.176.2.12]) by hub.freebsd.org (Postfix) with ESMTP id 6792F14C9D for ; Mon, 17 Jan 2000 06:41:02 -0800 (PST) (envelope-from Ariel.Burbaickij@mni.fh-giessen.de) Received: from caspar.mni.fh-giessen.de by merkur.hrz.uni-giessen.de with ESMTP for freebsd-questions@freebsd.org; Mon, 17 Jan 2000 15:40:54 +0100 Received: from sun9.mni.fh-giessen.de ([134.176.183.109]) by caspar.mni.fh-giessen.de with esmtp (Exim 2.12 #6) id 12ADL4-0003CK-00 for freebsd-questions@freebsd.org; Mon, 17 Jan 2000 15:41:02 +0100 Received: from localhost (hg9456@localhost) by sun9.mni.fh-giessen.de (8.9.3+Sun/8.8.8) with ESMTP id PAA00948 for ; Mon, 17 Jan 2000 15:41:34 +0100 (MET) X-Authentication-Warning: sun9.mni.fh-giessen.de: hg9456 owned process doing -bs Date: Mon, 17 Jan 2000 15:41:34 +0100 (MET) From: Ariel Burbaickij X-Sender: hg9456@sun9 To: freebsd-questions@freebsd.org Subject: understanding timing Message-Id: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG We got homework to implement shell.I am ready so far .So this mail is not begging for doing my work by anyone else :)).We got some solution pattern from out teacher suggesting following: void do_with_time(int argc,char * argv [])//function for doing it. { clock_t start ,end ; struct tm tnt ; pid_t pid1 ,pid2 //YTou already see here it is about using two forks. if(argc > 1)//we expect the coomand proper as well { pid1 = fork() switch(pid1) { case -1 : /* fear ,fire ,foes */ case 0 : { start = times(&tnt); pid2 = fork() switch(pid2) { case -1 : /* fear fire ,foes */ case 0 : { execvp(argv[1],&argv[1]); printf("You should never see me!"); } default: waitpid(pid,NULL,NULL) //quick and dirty end = times(&tnt); /* kind printf(Real time is difference between end and start); printf(System time is &time.tms_cstime);//evaluation order is //surely against us }//end of second switch default : waitpid(pid,NULL,NULL); }//end of first switch }//end of if else printf(You need at least two to dance tango); What i do not understand is why you need two fork's() already provided with waitpid()and so having mechanism for waiting for well-defined child,so eliminating the danger of cumulating the childrens' time in tms structrue.I would understand with wait() only.But here I guess I need a little help from you. kind regards, Ariel To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message