[erlang-questions] erlang port and C executable

Edwin Fine <>
Sun Nov 23 20:53:56 CET 2008


>
> > >I understand - I was pointing more to the idea than the implementation.
> I
> > >think Erlang/OTP should perhaps provide a standard wrapper C program
> that
> > >will run any program as a child, and has a back-channel that allows you
> to
> > >kill it (and its child) if the child becomes non-responsive.
> >
> > Perhaps, but they can't do everything for you - it's a trivial program
> > to write, except that there's a lot of little things that it should do
> > in different ways depending on your needs, which means that it will
> > become quite complex to use if it should cover everyone's needs.
> > E.g. does it need to "proxy" input and/or output for the child program?
> > Should it grab its stdio for this or use some other file descriptors?
> > What "protocol" should it talk on the port pipes back to Erlang? Etc.
> >
> > --Per
> _______________________________________________
>
>
>  Though not addressing all the questions above, here's an old
>  post from me regarding how I'm using open_port and killing the
>  spawned process ...
>
>
>
> http://www.trapexit.org/forum/viewtopic.php?p=30762&highlight=&sid=0cce5d6ad7c14306754ec99249fe912f
>
>
>  I use the technique to monitor a USB port.
>
>
>  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").
>
> port() ->
>   Port = open_port({spawn, ?DD },
>                    [eof, exit_status, use_stdio, binary]) ,
>
>   receive
>     {Portb, {data, Pid_with_lf}} ->
>     {ok, Pid_of_dd, 1} = regexp:gsub(binary_to_list(Pid_with_lf), "\n", "")
>   end ,
>
>   io:fwrite('~p~n', [{Portb, {data, Pid_with_lf}}]) ,
>
>   {Port, Pid_of_dd}
> .
>

Thanks - I read the trapexit post, too, and that's very interesting!! The
things you can do with dd! The mind boggles.
Edwin


>
> ~Michael
>
>
> --
> Michael McDaniel
> Portland, Oregon, USA
> http://autosys.us
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081123/0479f7e5/attachment.html>


More information about the erlang-questions mailing list