From owner-freebsd-questions Sun Feb 14 10:22:43 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id KAA21805 for freebsd-questions-outgoing; Sun, 14 Feb 1999 10:22:43 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from cd.mbn.or.jp (cd.mbn.or.jp [202.217.0.53]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA21787 for ; Sun, 14 Feb 1999 10:22:36 -0800 (PST) (envelope-from mariga@cd.mbn.or.jp) Received: from gateway (cse8-39.kokubunji.mbn.or.jp [210.144.135.63]) by cd.mbn.or.jp (8.9.1/cd.mbn.or.jp-2.0) with SMTP id DAA05306 for ; Mon, 15 Feb 1999 03:22:34 +0900 (JST) Message-ID: <000301be5845$ba8022e0$064ca8c0@gateway> From: "Masahiro Ariga" To: Subject: Please untangle my brain. Date: Mon, 15 Feb 1999 03:12:27 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.2106.4 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 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