[erlang-questions] Fwd: Report errors when using "-detached" option

Claes Wikstrom <>
Tue Nov 18 20:47:31 CET 2008


ERLANG wrote:
> Hi Nicolas,
> 
>>>> This is indeed a real problem. If daemon startup fails, you  
>>>> typically
>>>> want to indicate that through a call to exit(error_code) so that the
>>>> invoker can check $?
>>>>
>>> Hmmm. Calling "exit(error_code)" isn't reported to the invoker.
>>> So $? always equals to 0.
>>>
>>> Is this an expected behaviour of calling "exit(error_code)" when  
>>> using
>>> "-detached" flag.
>>>
>> halt(error_code) works.
> 
> No, It doesn't.
> 

Yes it does,

[]~ > erl
Erlang (BEAM) emulator version 5.6.5 [source] [smp:2] [async-threads:0] [kernel-poll:false]

Eshell V5.6.5  (abort with ^G)
1> halt(77).
[]~ > echo $?
77


But that's not the point. What's needed is to fork(), let the new code run
for a while and check config/whatever, if all is well it calls foo:bar(ok) and the
invoker eventually gets a status code 0, whereas if the forked process (beam)
calls foo:bar({error, Code}) the invoker of erl -detached2 ... gets Code
in the UNIX shell


/klacke




More information about the erlang-questions mailing list