Path: utzoo!attcan!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: Orphaned processes : Please explain Message-ID: <7586@star.cs.vu.nl> Date: 17 Sep 90 19:11:31 GMT References: <2140001@hpnmdla.HP.COM> <1990Sep15.133135.28744@virtech.uucp> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 39 In article <1990Sep15.133135.28744@virtech.uucp>, cpcahil@virtech.uucp (Conor P. Cahill) writes: )In article <2140001@hpnmdla.HP.COM> ) rajeev@hpnmdla.HP.COM (Rajeev Menon) writes: )> [ questions about pids, ppids, etc with forking processes deleted] ) )The key to your problem is that you can't be sure what process will )run first following a fork (maybe the parent, maybe the child). Right. )>Sometimes (as in case 2),the file "junk" does not contain output from all )>the processes. Why ? Now I do ) )The problem you had with missing output is that you have several )files opening & writing to the file at the same time, but you did not )set append mode on the file. Wrong. The file was only opened once. The forked processes shared a _common_ file offset (resulting in automatic append mode). The command sequences Rajeev used were: % cc fork.c ; a.out ; cat junk i=0, pid = 10779, ppid = 20487. i=2, pid = 10781, ppid = 10780. % cc fork.c ; a.out ; cat junk i=3, pid = 11122, ppid = 11121. i=2, pid = 11121, ppid = 11120. i=0, pid = 11119, ppid = 20487. i=1, pid = 11120, ppid = 11119. I suggest he try the following command sequence: % cc fork.c ; a.out ; sleep 10 ; cat junk Get my point? -- "That's right, you wanted the "Self-Destruct" button, to your left." (John Woods)