Hi Arjan! On 11 Jan 2006, at 13:51, Arjan van de Ven wrote:
you just cannot depend on which would run first, child or parent. Evenif linux would do it the other way around, you have no guarantee. ThinkSMP or Dual Core processors and time slices and cache misses... your code just HAS to be able to cope with it. Even on solaris ;)
That means that the starting of the child process needs to be synchronized by the application itself. I tried it once but then I discovered that my case was easily solved in a completely different way (it was a very small project). However, which one is the easiest/ fastest way to do this synchronization? Using SysV-Semaphores? Pipes? Would something like this work?
int fd[2], pid; pipe(fd); pid = fork(); if (pid < 0) { error(); } else if (pid == 0) { close(fd[1]); read(fd[0]); close(fd[0]); child_code(); } else { store_pid(); close(fd[0]); close(fd[1]); // this should wake up the child, right? } This should ensure that store_pid() is executed before child_code()... Ciao, Roland -- TU Muenchen, Physik-Department E18, James-Franck-Str., 85748 Garching Telefon 089/289-12575; Telefax 089/289-12570 -- UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. -Doug Gwyn -----BEGIN GEEK CODE BLOCK----- Version: 3.12GS/CS/M/MU d-(++) s:+ a-> C+++ UL++++ P+++ L+++ E(+) W+ !N K- w--- M + !V Y+
PGP++ t+(++) 5 R+ tv-- b+ DI++ e+++>++++ h---- y+++ ------END GEEK CODE BLOCK------
Attachment:
PGP.sig
Description: This is a digitally signed message part
- Follow-Ups:
- Re: OT: fork(): parent or child should run first?
- From: Lee Revell <[email protected]>
- Re: OT: fork(): parent or child should run first?
- References:
- OT: fork(): parent or child should run first?
- From: Gábor Lénárt <[email protected]>
- Re: OT: fork(): parent or child should run first?
- From: Arjan van de Ven <[email protected]>
- OT: fork(): parent or child should run first?
- Prev by Date: Re: [patch 4/5] Add MMC password protection (lock/unlock) support V3
- Next by Date: Re: Crash with SMP on post 2.6.15 -git kernel
- Previous by thread: Re: OT: fork(): parent or child should run first?
- Next by thread: Re: OT: fork(): parent or child should run first?
- Index(es):