[erlang-questions] erlang port and C executable

Michael McDaniel erlangy@REDACTED
Mon Nov 24 00:03:19 CET 2008


On Sun, Nov 23, 2008 at 10:30:30PM +0100, Per Hedeland wrote:
> Michael McDaniel <erlangy@REDACTED> wrote:
> >
> > In the original post I forgot to include the command I use to echo back
> > the PID;
> >
> > I get the PID using my port/0 command ...
> >
> >-define(IF, "/dev/ttyUSB0").
> >-define(DD, "/bin/dd if=" ++ ?IF ++ " bs=1 oflag=dsync& pid=$!; echo $pid").
> 
> That's generally fine, and actually pretty much exactly what I suggested
> earlier in the thread that Edwin pointed to (but it wasn't good enough
> *there*:-). There are a couple of gotchas though:
> 
> 1. Since you are running the "real" program in the background, you won't
>    get its exit status, i.e. this
> 
> >   Port = open_port({spawn, ?DD },
> >		    [eof, exit_status, use_stdio, binary]) ,
> 
>    will (eventually) give you the exit status of 'echo'. Could perhaps
>    be handled by ending the commandline with 'wait'.
> 
> 2. If the program starts producing output immediately, there's no
>    guarantee that
> 
> >   receive
> >     {Portb, {data, Pid_with_lf}} ->
> 
>    will have only the pid in Pid_with_lf - worst case it could have
>    output from the program, and not include the pid at all.
> 
> In your case I think neither of those is an actual problem, but it might
> be misleading for future readers of your code to include the exit_status
> option.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 Good points - thanks, Per, for pointing these out.

 For '1.' I do not presently care though '2.' would be a problem in my
 existing application if I did not get the PID at all.


~Michael


> 
> --Per






More information about the erlang-questions mailing list