<?xml version="1.0" encoding="utf-8" ?>

<?xml-stylesheet type="text/xsl" href="/templates/2k11/rss.xsl" media="screen" ?>
<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    
    <title>Daniel Lange's blog (Entries tagged as address)</title>
    <link>https://daniel-lange.com/</link>
    <description>agrep -pB IT /dev/life</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 2.6.0 - http://www.s9y.org/</generator>
    <pubDate>Fri, 06 Jun 2014 17:57:57 GMT</pubDate>

    <image>
    <url>//daniel-lange.com/uploads/Avatar_Blog_144_234.png</url>
    <title>RSS: Daniel Lange's blog - agrep -pB IT /dev/life</title>
    <link>https://daniel-lange.com/</link>
    <width>144</width>
    <height>234</height>
</image>

<item>
    <title>How much memory does a process use on Linux?</title>
    <link>https://daniel-lange.com/archives/93-How-much-memory-does-a-process-use-on-Linux.html</link>
            <category>Linux</category>
    
    <comments>https://daniel-lange.com/archives/93-How-much-memory-does-a-process-use-on-Linux.html#comments</comments>
    <wfw:comment>https://daniel-lange.com/wfwcomment.php?cid=93</wfw:comment>

    <slash:comments>3</slash:comments>
    <wfw:commentRss>https://daniel-lange.com/rss.php?version=2.0&amp;type=comments&amp;cid=93</wfw:commentRss>
    

    <author>nospam@example.com (Daniel Lange)</author>
    <content:encoded>
    &lt;p&gt;Sometimes the easy questions are the hardest to answer.&lt;/p&gt;

&lt;p&gt;Memory can mean RSS (Resident Set Size) which is the memory of a process held in RAM (so not swapped out).
That does include shared memory allocations. So if you add two RSS numbers, you&#039;re probably wrong already.
Still this is usually the number we look for in most practical investigations.&lt;/p&gt;

&lt;p&gt;Then there is VSZ (Virtual Set siZe) also called SIZE. The VSZ includes code, data and stack segments a process has allocated.
And again that will count &lt;em&gt;some&lt;/em&gt; shared address space. So usually bash will have a VSZ that&#039;s lower than its RSS.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;man ps&lt;/code&gt; will also tell you:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;   The SIZE and RSS fields don&#039;t count some parts of a process including the page tables, kernel stack, struct
   thread_info, and struct task_struct.  This is usually at least 20 KiB of memory that is always resident.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In most (if not all) practical scenarios that difference won&#039;t matter. If it were, you&#039;d be using &lt;code&gt;valgrind&lt;/code&gt; to look into the memory usage of your application in minute detail. Wouldn&#039;t you?&lt;/p&gt;

&lt;p&gt;If you want to have an as-detailed-as-possible look into the memory allocations of a process &lt;code&gt;pmap &amp;lt;pid&amp;gt;&lt;/code&gt; will give you the information.
The summary at the end is a gross over-estimation of the total memory a process has allocated as it counts all mapped memory (and may still be wrong due to de-duplication and other factors). But that number may well serve as an upper bound if you need something like that.&lt;/p&gt;

&lt;p&gt;For running processes&lt;/p&gt;

&lt;div class=&quot;bash geshi&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;ps&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-eo&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;pid user rss:8 size:8 cmd&#039;&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;--sort&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;rss&#039;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;/div&gt;

&lt;p&gt;will give you a nice sorted list of processes and their RSS and VSZ (SIZE) in kiB (old school &lt;a href=&quot;http://en.wikipedia.org/wiki/Kibibyte&quot; title=&quot;Wikipedia article: Kibibytes&quot;&gt;kB&lt;/a&gt;...).&lt;/p&gt;

&lt;p&gt;For short running commands GNU &lt;code&gt;time&lt;/code&gt; (not the bash build-in &lt;code&gt;time&lt;/code&gt; command, &lt;code&gt;apt install time&lt;/code&gt; on Debian-based systems) has a nice capability that&#039;s not widely known yet:&lt;/p&gt;

&lt;div class=&quot;bash geshi&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;usr&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;bin&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;time&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-f&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;RSS: %MkiB&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;command&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;/div&gt;

&lt;p&gt;will tell you the maximum RSS size the &lt;code&gt;&amp;lt;command&amp;gt;&lt;/code&gt; has had during its lifetime. That&#039;s better than &lt;code&gt;top&lt;/code&gt; or &lt;code&gt;watch ps&lt;/code&gt; and trying to spot the process.&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Fri, 06 Jun 2014 17:45:00 +0000</pubDate>
    <guid isPermaLink="false">https://daniel-lange.com/archives/93-guid.html</guid>
    <category>address</category>
<category>linux</category>
<category>memory</category>
<category>ram</category>

</item>
<item>
    <title>Binding applications to a specific IP</title>
    <link>https://daniel-lange.com/archives/53-Binding-applications-to-a-specific-IP.html</link>
            <category>Linux</category>
    
    <comments>https://daniel-lange.com/archives/53-Binding-applications-to-a-specific-IP.html#comments</comments>
    <wfw:comment>https://daniel-lange.com/wfwcomment.php?cid=53</wfw:comment>

    <slash:comments>22</slash:comments>
    <wfw:commentRss>https://daniel-lange.com/rss.php?version=2.0&amp;type=comments&amp;cid=53</wfw:commentRss>
    

    <author>nospam@example.com (Daniel Lange)</author>
    <content:encoded>
    &lt;p&gt;These days many systems are multi-homed in the sense that they have more than one IP address bound at the same time.&lt;br /&gt;
I.e. for different network cards, virtual IPs for shared servers or just using WiFi and a wired network connection at the same time on a laptop.&lt;/p&gt;

&lt;p&gt;Murphy of course makes sure that your system will choose to worst IP (i.e. that on slow WiFi or the one reserved for admin access) when an application does not specifically supports binding to a selected IP address.
And Mozilla Firefox for example doesn&#039;t.&lt;/p&gt;

&lt;p&gt;The kernel chooses an outgoing IP from those in the routing table with the same metric:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;daniel@server:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.0.2.1         0.0.0.0         U     0      0        0 eth0
0.0.0.0         192.0.2.2         0.0.0.0         U     0      0        0 eth1
0.0.0.0         192.0.2.3         0.0.0.0         U     0      0        0 eth2
0.0.0.0         192.0.2.4         0.0.0.0         U     0      0        0 eth3
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can obviously play around with the metric and make the kernel router prefer the desired interface above others. This will affect all applications though.
Some people use the firewall to nat all packages to port 80 onto the network interface desired for web browsing. Gee, beware the http://somewebsite.tld:8080 links...&lt;/p&gt;

&lt;p&gt;Thankfully &lt;a href=&quot;http://www.ryde.net&quot; title=&quot;Daniel Ryde&#039;s homepage&quot;&gt;Daniel Ryde&lt;/a&gt; has solved the problem via a LD_PRELOAD shim. With his code you can run&lt;/p&gt;

&lt;div class=&quot;bash geshi&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #666666;&quot;&gt;daniel@laptop:~$ &lt;/span&gt;&lt;span style=&quot;color: #007800;&quot;&gt;BIND_ADDR&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;192.0.2.100&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #007800;&quot;&gt;LD_PRELOAD&lt;/span&gt;=&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;usr&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;lib&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;bind.so firefox &lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;

&lt;p&gt;and happily surf away.&lt;/p&gt;

&lt;p&gt;To compile &lt;a href=&quot;http://www.ryde.net/code/bind.c.txt&quot; title=&quot;Bind.c LD_PRELOAD wrapper&quot;&gt;his code&lt;/a&gt; (3.3kB, &lt;a href=&quot;https://daniel-lange.com/software/bind.c&quot; title=&quot;Local copy of Daniel Ryde&#039;s Bind.c LD_PRELOAD wrapper&quot;&gt;local copy&lt;/a&gt;, see note 1)
you need to run&lt;/p&gt;

&lt;div class=&quot;bash geshi&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;gcc&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-nostartfiles&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-fpic&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-shared&lt;/span&gt; bind.c &lt;span style=&quot;color: #660033;&quot;&gt;-o&lt;/span&gt; bind.so &lt;span style=&quot;color: #660033;&quot;&gt;-ldl&lt;/span&gt; -D_GNU_SOURCE&lt;br /&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;strip&lt;/span&gt; bind.so&lt;br /&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;cp&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-i&lt;/span&gt; bind.so &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;usr&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;lib&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;&lt;/div&gt;

&lt;p&gt;and you&#039;re set to go.&lt;/p&gt;

&lt;p&gt;If you don&#039;t have gcc available (and trust me) you can download pre-compiled 32bit and 64bit (glibc-2) bind.so libraries &lt;a href=&quot;https://daniel-lange.com/software/bind_so_compiled.tar.gz&quot; title=&quot;Pre-compiled 32bit and 64bit bind.so libs&quot;&gt;here&lt;/a&gt; (4.5kB).&lt;/p&gt;

&lt;p&gt;I guess because Daniel Ryde hid his code so well on his webpage, Robert J. McKay wrote another LD_PRELOAD shim, called &lt;a href=&quot;http://wari.mckay.com/~rm/bindhack.c.txt&quot; title=&quot;Bindhack.c LD_PRELOAD wrapper&quot;&gt;Bindhack&lt;/a&gt; (4.5kB, &lt;a href=&quot;https://daniel-lange.com/software/bindhack.c&quot; title=&quot;Local mirror of Robert J. McKay&#039;s Bindhack.c LD_PRELOAD wrapper&quot;&gt;local mirror&lt;/a&gt;). This will - as is - only compile on 32bit machines. But YMMV.&lt;/p&gt;

&lt;p&gt;Run the above command &lt;strong&gt;(&amp;#42;)&lt;/strong&gt; with your desired (and locally bound) IP address in bash and visit &lt;a href=&quot;http://myip.dk&quot; title=&quot;MyIP.dk show-your-ip service&quot;&gt;MyIP.dk&lt;/a&gt; or &lt;a href=&quot;http://en.dnstools.ch/show-my-ip.html&quot; title=&quot;DNStools.ch show-your-ip service&quot;&gt;DNStools.ch&lt;/a&gt; or any of the other services that show your external IP to see whether you&#039;ve succeeded.&lt;/p&gt;

&lt;p&gt;Notes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Daniel Ryde did not specify the -D_GNU_SOURCE in the comments section of bind.c. Modern glibc/gcc need that as he used RTLD_NEXT which is Unix98 and not POSIX. I amended the local copy of bind.c and sent him an email so he can update his.&lt;/li&gt;
&lt;li&gt;Both are IPv4 only, no IPv6 support.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;Updates:&lt;/h3&gt;

&lt;p&gt;19.03.15 madmakz wrote in to clarify that all of the bind LD_PRELOAD shims only work with TCP connections. So &lt;strong&gt;not&lt;/strong&gt; with UDP.&lt;br /&gt;
I&#039;m not aware of a shim that manipulates UDP sockets.&lt;/p&gt;

&lt;p&gt;14.01.14 Christian Pellegrin wrote a superb &lt;a href=&quot;http://www.evolware.org/?p=293&quot; title=&quot;Article: Using Linux Network Namespaces for per processes routing&quot;&gt;article&lt;/a&gt; on how to achieve per-application routing with the help of Linux network namespaces.&lt;/p&gt;

&lt;p&gt;16.06.13 showip.be seems to be gone, so I replaced it with dnstools.ch in the text above. There are &lt;a href=&quot;http://www.google.com/search?q=show+my+ip&quot; title=&quot;Google for see-your-external-IP services&quot;&gt;plenty of others&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;22.06.12 Lennart Poettering has a IPv4 only version of a shim and a rather good readme available at &lt;a href=&quot;http://0pointer.de/lennart/projects/fixsrcip/&quot; title=&quot;Lennart Poettering&#039;s FixSrcIP&quot;&gt;his site&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;29.11.10 Catalin M. Boie wrote another LD_PRELOAD shim, &lt;a href=&quot;http://kernel.embedromix.ro/us/&quot; title=&quot;Catalin(ux) Homepage&quot;&gt;force_bind&lt;/a&gt;. I have not tested this one. It&#039;s capable of handling IPv6 binds.&lt;/p&gt;

&lt;p&gt;11.01.09 Daniel Ryde has replied to my email and updated his local copy now as well.&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Sat, 09 Jan 2010 19:00:00 +0000</pubDate>
    <guid isPermaLink="false">https://daniel-lange.com/archives/53-guid.html</guid>
    <category>address</category>
<category>bind</category>
<category>ip</category>
<category>ld_preload</category>
<category>multi-homed</category>
<category>network</category>
<category>updated</category>

</item>

</channel>
</rss>
