[erlang-questions] Call erlang:port_info/1 from shell

Andy W. Song <>
Wed Jun 22 17:28:22 CEST 2011


Thanks, it works very well.
When I call PortInfo(868) I get:
[{name,"tcp_inet"},
 {links,[<0.234.0>]},
 {id,868},
 {connected,<0.234.0>},
 {input,0},
 {output,12788}]

So here comes my next question: how can I find out the socket information
associated to this port, such as ip and port?

Thanks
Andy


2011/6/22 Allen Kim <>

> I believe c:pid/3 is given to you for convenience of debugging.
> I don't think there is one that converts list(string) to port, and I also
> think we do not convert string to port in code.
>
> since it is shell environment you want to run on,  I don't think
> performance really matters.
> If so, you can use a simple function like this.
>
> PortInfo = fun(Num) ->
>    [MyPort] =lists:filter(fun(Port) -> {id,PortNum} =
> erlang:port_info(Port,id), PortNum==Num end, erlang:ports()),
>    erlang:port_info(MyPort)
> end.
>
> PortInfo(267).
>
> Allen
>
> From: "Andy W. Song" <>
>  Date: Wed, 22 Jun 2011 09:07:18 -0500
> To: Allen Kim <>
> Subject: Re: [erlang-questions] Call erlang:port_info/1 from shell
>
> This is not convenient. I can use pid(0,22222,0) to get a pid from shell. I
> suppose there should be a similar way for ports. If have thousands of ports,
> which I do, and I just want to examine one of them from shell, I can't walk
> through them.
>
> 2011/6/22 Allen Kim <>
>
>> [ erlang:port_info(Port) || Port <- erlang:ports()].
>>
>> You can also use lists:foreach instead.
>>
>> From: "Andy W. Song" <>
>> Date: Wed, 22 Jun 2011 08:49:30 -0500
>> To: erlang-questions <>
>> Subject: [erlang-questions] Call erlang:port_info/1 from shell
>>
>> Hi,
>>
>> If I run erlang:ports() from shell, it shows
>>
>> [#Port<0.1>,#Port<0.113>,#Port<0.118>,#Port<0.125>,
>>  #Port<0.513>,#Port<0.526>,#Port<0.201852>,#Port<0.202767>,
>>  #Port<0.202768>,#Port<0.202769>,#Port<0.202770>,
>>  #Port<0.202771>,#Port<0.202772>,#Port<0.202773>,
>>  #Port<0.202774>,#Port<0.202775>,#Port<0.202776>,
>>  #Port<0.202777>,#Port<0.202778>,#Port<0.202779>,
>>  #Port<0.202780>,#Port<0.202781>,#Port<0.202782>,
>>  #Port<0.202783>,#Port<0.202784>,#Port<0.202785>,
>>  #Port<0.202786>,#Port<0.202787>,#Port<0.202788>|...]
>>
>> Now I want to call erlang:port_info/1, but I don't know how to build the
>> Port() parameter from say #Port<0.513>. Can anybody help? And BTW, where
>> should I look for the document about this kind of thing?
>>
>> Thanks
>> Andy
>>
>> --
>> ---------------------------------------------------------------
>> 有志者,事竟成,破釜沉舟,百二秦关终属楚
>> 苦心人,天不负,卧薪尝胆,三千越甲可吞吴
>>
>>
>
>
> --
> ---------------------------------------------------------------
> 有志者,事竟成,破釜沉舟,百二秦关终属楚
> 苦心人,天不负,卧薪尝胆,三千越甲可吞吴
>
>


-- 
---------------------------------------------------------------
有志者,事竟成,破釜沉舟,百二秦关终属楚
苦心人,天不负,卧薪尝胆,三千越甲可吞吴
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110622/5f8cfc52/attachment.html>


More information about the erlang-questions mailing list