Orphaned processes : Please explain

Maarten Litmaath maart at cs.vu.nl
Tue Sep 18 05:11:31 AEST 1990


In article <1990Sep15.133135.28744 at virtech.uucp>,
	cpcahil at virtech.uucp (Conor P. Cahill) writes:
)In article <2140001 at hpnmdla.HP.COM>
)	rajeev at 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)



More information about the Comp.unix.questions mailing list