On 22 November 2012 16:04, Max Leske <[email protected]> wrote:
>
> On 22.11.2012, at 12:28, Igor Stasenko <[email protected]> wrote:
>
>> On 22 November 2012 11:19, Max Leske <[email protected]> wrote:
>>> I have run into a small problem with fork():
>>>
>>>        pid := self primitiveRun.
>>>        pid isZero
>>>                ifTrue: [ "child code with exec" ]
>>>                ifFalse: [ "parent code" ]
>>>
>>>        primitiveRun
>>>         <primitive: #primitiveNativeCall module: #NativeBoostPlugin>
>>>         ^ self nbCall: #( int fork() )
>>>
>>> Only the parent code is ever executed, #pid is never 0.
>>
>> are you sure about that?
>> if you evaluate
>> self fork
>> it will always answer non-zero.. because it is parent process,
>> where you observing result.
>> But that doesnt means that there is no child process which observes
>> different return value.
>
> Assuming that I wouldn't be able to observer when #pid is 0, then the 
> following should still work:
>
>         pid := self primitiveRun.
>         pid isZero
>                ifTrue: [ StandardFileStream forceNewFileNamed: 'foo.log' ]  
> <-----------------------
>                ifFalse: [ "parent code" ]
>
> The file 'foo.log' is never created.
>
> The UnixOSProcessPlugin has pretty much the same code:
>
>         ((pid := self cCode: 'vfork()') = 0)
>                 ifFalse:
>                         [ "child code" ]
>                 ifTrue:
>                         [ "parent code" ]
>
> BTW: using vfork() instead of fork() (as OSProcess does) doesn't work either 
> (the image hangs as expected but the file 'foo.log' is not created).
>
what you mean image hangs? do you see if child process created?


-- 
Best regards,
Igor Stasenko.

Reply via email to