Date: Mon, 17 Jan 2000 15:41:34 +0100 (MET) From: Ariel Burbaickij <Ariel.Burbaickij@mni.fh-giessen.de> To: freebsd-questions@freebsd.org Subject: understanding timing Message-ID: <Pine.GSO.4.10.10001171521100.807-100000@sun9>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.10.10001171521100.807-100000>