Date: Mon, 15 Feb 1999 03:12:27 +0900 From: "Masahiro Ariga" <mariga@cd.mbn.or.jp> To: <freebsd-questions@FreeBSD.ORG> Subject: Please untangle my brain. Message-ID: <000301be5845$ba8022e0$064ca8c0@gateway>
next in thread | raw e-mail | index | archive | help
My name is Masahiro Ariga, I know this is concerned with UNIX itself rather than FREE BSD,so I am afraid this is not the proper site to ask but I am in a predicament so I beseech senior UNIX explorer to teach me. I assume UNIX runs on time-sharing system,changing processs every time.In order to trace process change movement,I made the next program. #include <stdio.h> main() { int i; if(fork()==0){ /* Child Process */ for(i=0;i<5;i++){ printf("This is child! num=%d\n",i); } exit(0); } else{ /* Parent Process */ for(i=0;i<5;i++){ printf("This is parent! num=%d\n",i); } } } And made it run,expecting the output should be as follows, This is child! num=0 This is parent! num=0 This is child! num=1 This is parent! num=1 and so on,but instead the actual output was as follows. This is child! num=0 This is child! num=1 This is child! num=2 This is child! num=3 This is child! num=4 This is parent! num=0 This is parent! num=1 This is parent! num=2 This is parent! num=3 This is parent! num=4 I am puzzeled.Why in the world this could happen,what was going in UNIX?Please someone untangle my mystified brain. And if someone knows how to write program to correctly trace process's change movement(using IPC,semaphor or whatsoever),please let me know. Also,if someone knows the proper site for me to ask these UNIX programing,would you pleas tell me. Sincerely yours, My E-mail address is, mariga@cd.mbn.or.jp 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?000301be5845$ba8022e0$064ca8c0>