<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-28076022</id><updated>2011-08-07T10:48:49.627+08:00</updated><category term='linux'/><category term='www'/><category term='shell script'/><category term='solaris'/><category term='multimedia'/><category term='networking'/><category term='security'/><category term='misc'/><category term='programming'/><title type='text'>Ah Lam's Note</title><subtitle type='html'>I am a software developer working in Hong Kong. This blog is for sharing my 2 cents IT knowledge.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ahlamnote.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>48</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-28076022.post-2119817941802756542</id><published>2007-08-25T08:52:00.000+08:00</published><updated>2007-08-25T09:09:53.084+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='networking'/><title type='text'>MTU is really a matter</title><content type='html'>Long time ago, I lower the MTU of my router to solve a networking issue (&lt;a href="http://ahlamnote.blogspot.com/2006/01/does-mtu-matter.html"&gt;see my previous blog entry&lt;/a&gt;). However, it is not the end of story.&lt;br /&gt;Recently, I have changed my job. My new company provides &lt;a href="http://en.wikipedia.org/wiki/Citrix_Presentation_Server" title="Citrix Presentation Server"&gt;Citrix Presentation Server&lt;/a&gt; for employees to work at home via remote desktop.&lt;br /&gt;Then, at home, I tried to connect to Citrix server and run remote desktop. I can login but the link is very unstable. It disconnected every 10 to 20 seconds.&lt;br /&gt;After some investigation, I found it is the MTU problem again. The problem is fully explained at the following site:&lt;br /&gt;&lt;a href="http://www.netheaven.com/pmtu.html"&gt;http://www.netheaven.com/pmtu.html&lt;/a&gt;&lt;br /&gt;I should change the MTU of my desktop at home to match the router. Finally, it works!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-2119817941802756542?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=2119817941802756542' title='38 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/2119817941802756542'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/2119817941802756542'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/08/mtu-is-really-matter.html' title='MTU is really a matter'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>38</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-960032292120496885</id><published>2007-07-01T09:59:00.000+08:00</published><updated>2007-07-01T10:13:20.089+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Boost C++ Libraries</title><content type='html'>Recently, I checked some job ad. on the web and found some jobs require knowledge about "Boost". I have not heard "Boost" before. After some googling, I visit the web site of &lt;a href="http://www.boost.org/"&gt;Boost&lt;/a&gt;. Boost is really a great thing. It is a set of C++ libraries contains many useful programming constructs with good documentation, e.g. smart pointers, regular expression, object pools, state machines....  Lastly, it is open source and free.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-960032292120496885?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=960032292120496885' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/960032292120496885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/960032292120496885'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/07/boost-c-libraries.html' title='Boost C++ Libraries'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-4204222202123832889</id><published>2007-06-17T11:27:00.000+08:00</published><updated>2007-06-17T11:44:37.054+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Dig out dead looping thread</title><content type='html'>It is not easy to write multi-threading applications. One of the common bugs is dead looping of a thread. To kill this kind of bugs, the first step is to find out which thread causes dead looping. However, an application may have dozens of threads. How to dig out the dead looping thread? My trick is to issue the &lt;code&gt;ps -eLf&lt;/code&gt; command to list the information of threads in the whole system. The "time" column of the output of &lt;code&gt;ps&lt;/code&gt; shows the CPU time have spent by the threads. Most likely, the dead looping thread would be the thread spending most CPU time. Then, drop down the  LWP number of the thread. Next, you use gdb to attach the process and to debug the thread.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-4204222202123832889?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=4204222202123832889' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4204222202123832889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4204222202123832889'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/06/dig-out-dead-looping-thread.html' title='Dig out dead looping thread'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-6021182752348678291</id><published>2007-06-10T11:16:00.000+08:00</published><updated>2007-06-10T11:25:53.512+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='misc'/><title type='text'>Job Interview Questions</title><content type='html'>Recently, I got some job interviews. The interviewers asked me tones of questions. Most of them were very technical. The most difficult question was an IQ puzzle. Under stress, it is difficult to &lt;span style="font-style: italic;"&gt;overclock&lt;/span&gt; my brain :&lt;&lt;br /&gt;At home, I found a web site which included the IQ puzzle:&lt;br /&gt;&lt;a href="http://www.techinterview.org/index.html"&gt;http://www.techinterview.org/index.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-6021182752348678291?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=6021182752348678291' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/6021182752348678291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/6021182752348678291'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/06/job-interview-questions.html' title='Job Interview Questions'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-4749334026902234150</id><published>2007-05-12T13:38:00.000+08:00</published><updated>2007-05-12T14:04:00.821+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Undefined symbols in C++</title><content type='html'>In C++ programming, we sometimes encounter "undefined symbols" problem during compilation or dlopen. The name of undefined symbols looks obfuscated. E.g.:&lt;br /&gt;&lt;pre&gt;Unable to dlopen(test.so): test.so: Undefined symbol "_ZN6moduleD2Ev"&lt;/pre&gt;You may wonder why the symbol looks so ugly. Actually, this conversion of symbol is called &lt;a href="http://en.wikipedia.org/wiki/Name_mangling"&gt;name mangling&lt;/a&gt;. C++ supports polymorphism, this means functions can have same name but different types and numbers of parameters. Therefore, compiler cannot just use the function name as the symbol. Instead, both function name and parameter types should be included in symbol naming. Name mangling is the technique to encode a function name and parameter types into one symbol.&lt;br /&gt;&lt;br /&gt;To translate the mangled symbols to more meaningful text, we can use the &lt;code&gt;c++flit&lt;/code&gt; utility. E.g.&lt;br /&gt;&lt;pre&gt;ahlam@oxygen:~$ c++filt _ZN6moduleD2Ev&lt;br /&gt;module::~module()&lt;/pre&gt;Now, you know "_ZN6moduleD2Ev" is the destructor of &lt;code&gt;class module&lt;/code&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-4749334026902234150?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=4749334026902234150' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4749334026902234150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4749334026902234150'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/05/undefined-symbols-in-c.html' title='Undefined symbols in C++'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-2530432968506226317</id><published>2007-05-11T21:44:00.000+08:00</published><updated>2007-05-11T21:56:48.908+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>More than "command not found"</title><content type='html'>In old days, if I try to run a command which doesn't exist in my Linux box, it just prompts "command not found". Today, Ubuntu gives me a nice response:&lt;br /&gt;&lt;pre&gt;ahlam@oxygen:/usr/bin$ cdecl&lt;br /&gt;The program 'cdecl' can be found in the following packages:&lt;br /&gt;* cutils&lt;br /&gt;* cdecl&lt;br /&gt;Try: sudo apt-get install &amp;lt;selected package&amp;gt;&lt;br /&gt;Make sure you have the 'universe' component enabled&lt;br /&gt;bash: cdecl: command not found&lt;/pre&gt;&lt;br /&gt;It's surprising!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-2530432968506226317?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=2530432968506226317' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/2530432968506226317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/2530432968506226317'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/05/more-than-command-not-found.html' title='More than &quot;command not found&quot;'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-730864424893820749</id><published>2007-05-09T17:28:00.000+08:00</published><updated>2007-05-09T17:56:52.046+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Using new Chinese fonts from M$</title><content type='html'>One of my friends told me that the Chinese fonts in M$ Vista is much more beautiful. So, I try to install the fonts to my Ubuntu box today. The new Chinese fonts called YaHei and JhengHei. If you don't have Vista, you can download from &lt;a href="http://pool.upsdn.net/linux/fontconfig/fonts/"&gt;somewhere&lt;/a&gt; (:P). The screenshot below shows the result.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_swgiJf5zUz0/RkGVx5NBQHI/AAAAAAAAABw/ejikHJRzQuc/s1600-h/chinese_font.gif"&gt;&lt;img style="cursor: pointer;" src="http://4.bp.blogspot.com/_swgiJf5zUz0/RkGVx5NBQHI/AAAAAAAAABw/ejikHJRzQuc/s320/chinese_font.gif" alt="" id="BLOGGER_PHOTO_ID_5062492140542705778" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;For details about how to install the new fonts, you can refer to &lt;a href="http://imtx.cn/feed.php?go=entry_332"&gt;http://imtx.cn/feed.php?go=entry_332 &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-730864424893820749?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=730864424893820749' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/730864424893820749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/730864424893820749'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/05/using-new-chinese-fonts-from-m.html' title='Using new Chinese fonts from M$'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_swgiJf5zUz0/RkGVx5NBQHI/AAAAAAAAABw/ejikHJRzQuc/s72-c/chinese_font.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-3392644097352440977</id><published>2007-04-22T06:42:00.000+08:00</published><updated>2007-04-22T07:09:01.586+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Upgrade to Ubuntu 7.04</title><content type='html'>Yesterday, I follow the instruction &lt;a href="http://www.ubuntu.com/getubuntu/upgrading"&gt;here&lt;/a&gt; to upgrade my Ubuntu to 7.04. Unfortunately, the Update Manager crashes during package installation. To solve the problem, I use the following command:&lt;br /&gt;&lt;pre&gt;dpkg --configure -a&lt;/pre&gt;&lt;br /&gt;Then, I reboot the Linux box. Some errors occurs. It fails to mount all partitions, excepts "/" partition. After some investigation, under the new kernel (2.6.20), IDE harddisks/CD-ROM are considered as SCSI. The following is the &lt;code&gt;dmesg&lt;/code&gt; output:&lt;br /&gt;&lt;pre&gt;ata1: PATA max UDMA/100 cmd 0x000101f0 ctl 0x000103f6 bmdma 0x0001f000 irq 14&lt;br /&gt;ata2: PATA max UDMA/100 cmd 0x00010170 ctl 0x00010376 bmdma 0x0001f008 irq 15&lt;br /&gt;scsi0 : ata_piix&lt;br /&gt;ata1.00: ata_hpa_resize 1: sectors = 156301488, hpa_sectors = 156301488&lt;br /&gt;ata1.00: ATA-6: WDC WD800BB-55HEA0, 13.03G13, max UDMA/100&lt;br /&gt;ata1.00: 156301488 sectors, multi 16: LBA &lt;br /&gt;ata1.00: ata_hpa_resize 1: sectors = 156301488, hpa_sectors = 156301488&lt;br /&gt;ata1.00: configured for UDMA/100&lt;br /&gt;scsi1 : ata_piix&lt;br /&gt;ATA: abnormal status 0x7F on port 0x00010177&lt;br /&gt;ata2.01: ATAPI, max UDMA/33&lt;br /&gt;ata2.01: configured for UDMA/33&lt;br /&gt;&lt;b&gt;scsi 0:0:0:0: Direct-Access     ATA      WDC WD800BB-55HE 13.0 PQ: 0 ANSI: 5&lt;br /&gt;scsi 1:0:1:0: CD-ROM                     RW-481248        1.00 PQ: 0 ANSI: 5&lt;/b&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Therefore, the entries in &lt;code&gt;/etc/fstab&lt;/code&gt; should be changed from "/dev/hda&lt;span style="font-style: italic;"&gt;n&lt;/span&gt;" to "/dev/sda&lt;span style="font-style: italic;"&gt;n&lt;/span&gt;".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-3392644097352440977?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=3392644097352440977' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3392644097352440977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3392644097352440977'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/04/upgrade-to-ubuntu-704.html' title='Upgrade to Ubuntu 7.04'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-5364100914395747753</id><published>2007-04-19T19:53:00.000+08:00</published><updated>2007-04-19T20:24:51.165+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Know more about a process</title><content type='html'>Today, I would like to introduce some ways to get more information of a process, and hope those can help in trouble-shooting and debugging.&lt;br /&gt;&lt;h4&gt;List environment variables&lt;/h4&gt;&lt;br /&gt;To list the environment variables of a process you can issue the command:&lt;br /&gt;&lt;code&gt;ps ewww &lt;i&gt;pid&lt;/i&gt;&lt;/code&gt;&lt;br /&gt;E.g.:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;ahlam@oxygen:~/test/malloc$ ps ewww 4752&lt;br /&gt;PID TTY      STAT   TIME COMMAND&lt;br /&gt;4752 pts/2    Ss+    0:00 bash USER=ahlam HOME=/home/ahlam DESKTOP_SESSION=default GDM_XSERVER_LOCATION=loca&lt;br /&gt;l GTK_IM_MODULE=gcin LOGNAME=ahlam USERNAME=ahlam GDM_LANG=en_HK.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/u&lt;br /&gt;sr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games DISPLAY=:0.0 LANG=en_HK.UTF-8 XMODIFIERS=@im=gcin XAUTHOR&lt;br /&gt;ITY=/home/ahlam/.Xauthority SHELL=/bin/bash GDMSESSION=default QT_IM_MODULE=gcin PWD=/home/ahlam SSH_AUTH_SOC&lt;br /&gt;K=/tmp/ssh-nRdglP4521/agent.4521 SSH_AGENT_PID=4563 DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-ix9My5o6&lt;br /&gt;DJ,guid=8abd2646dc897f03d1cfb07e3a3d4b00 GTK_RC_FILES=/etc/gtk/gtkrc:/home/ahlam/.gtkrc-1.2-gnome2 SESSION_MA&lt;br /&gt;NAGER=local/oxygen:/tmp/.ICE-unix/4521 GNOME_KEYRING_SOCKET=/tmp/keyring-fXmYul/socket GNOME_DESKTOP_SESSION_&lt;br /&gt;ID=Default TERM=xterm COLORTERM=gnome-terminal WINDOWID=31457489&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;List out the threads of a process&lt;/h4&gt;&lt;br /&gt;&lt;code&gt;ps ms &lt;i&gt;pid&lt;/i&gt;&lt;/code&gt;&lt;br /&gt;E.g:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;ahlam@oxygen:~/test/malloc$ ps ms 4752&lt;br /&gt;UID   PID          PENDING          BLOCKED          IGNORED           CAUGHT STAT TTY        TIME COMMAND&lt;br /&gt;1000  4752 0000000000000000                -                -                - -    pts/2      0:00 bash&lt;br /&gt;1000     - 0000000000000000 0000000000000000 0000000000384004 000000004b813efb Ss+  -          0:00 -&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Print the memory map&lt;/h4&gt;&lt;br /&gt;To list the memory map of a process, you can use the &lt;code&gt;pmap&lt;/code&gt; command. It lists out the mapped memory regions and the purpose of the memory regions. It also lists out the .so files loaded by the process.&lt;br /&gt;&lt;code&gt;pmap &lt;i&gt;pid&lt;/i&gt;&lt;/code&gt;&lt;br /&gt;E.g:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;ahlam@oxygen:~/test/malloc$ pmap 4752&lt;br /&gt;4752:   bash&lt;br /&gt;08048000    644K r-x--  /bin/bash&lt;br /&gt;080e9000     20K rw---  /bin/bash&lt;br /&gt;080ee000   1804K rw---    [ anon ]&lt;br /&gt;b7c94000     36K r-x--  /lib/tls/i686/cmov/libnss_files-2.4.so&lt;br /&gt;b7c9d000      8K rw---  /lib/tls/i686/cmov/libnss_files-2.4.so&lt;br /&gt;b7c9f000     32K r-x--  /lib/tls/i686/cmov/libnss_nis-2.4.so&lt;br /&gt;b7ca7000      8K rw---  /lib/tls/i686/cmov/libnss_nis-2.4.so&lt;br /&gt;b7ca9000     72K r-x--  /lib/tls/i686/cmov/libnsl-2.4.so&lt;br /&gt;b7cbb000      8K rw---  /lib/tls/i686/cmov/libnsl-2.4.so&lt;br /&gt;b7cbd000      8K rw---    [ anon ]&lt;br /&gt;b7cbf000     28K r-x--  /lib/tls/i686/cmov/libnss_compat-2.4.so&lt;br /&gt;b7cc6000      8K rw---  /lib/tls/i686/cmov/libnss_compat-2.4.so&lt;br /&gt;b7cd7000    204K r----  /usr/lib/locale/en_HK.utf8/LC_CTYPE&lt;br /&gt;b7d0a000      4K r----  /usr/lib/locale/en_HK.utf8/LC_NUMERIC&lt;br /&gt;b7d0b000      4K r----  /usr/lib/locale/en_HK.utf8/LC_TIME&lt;br /&gt;b7d0c000    860K r----  /usr/lib/locale/en_HK.utf8/LC_COLLATE&lt;br /&gt;b7de3000      8K rw---    [ anon ]&lt;br /&gt;b7de5000   1204K r-x--  /lib/tls/i686/cmov/libc-2.4.so&lt;br /&gt;b7f12000      8K r----  /lib/tls/i686/cmov/libc-2.4.so&lt;br /&gt;b7f14000      8K rw---  /lib/tls/i686/cmov/libc-2.4.so&lt;br /&gt;b7f16000     12K rw---    [ anon ]&lt;br /&gt;b7f19000      8K r-x--  /lib/tls/i686/cmov/libdl-2.4.so&lt;br /&gt;b7f1b000      8K rw---  /lib/tls/i686/cmov/libdl-2.4.so&lt;br /&gt;b7f1d000    220K r-x--  /lib/libncurses.so.5.5&lt;br /&gt;b7f54000     32K rw---  /lib/libncurses.so.5.5&lt;br /&gt;b7f5c000      4K rw---    [ anon ]&lt;br /&gt;b7f5d000      4K r----  /usr/lib/locale/en_HK.utf8/LC_MONETARY&lt;br /&gt;b7f5e000      4K r----  /usr/lib/locale/en_HK.utf8/LC_MESSAGES/SYS_LC_MESSAGES&lt;br /&gt;b7f5f000      4K r----  /usr/lib/locale/en_HK.utf8/LC_PAPER&lt;br /&gt;b7f60000      4K r----  /usr/lib/locale/en_HK.utf8/LC_NAME&lt;br /&gt;b7f61000      4K r----  /usr/lib/locale/en_HK.utf8/LC_ADDRESS&lt;br /&gt;b7f62000      4K r----  /usr/lib/locale/en_HK.utf8/LC_TELEPHONE&lt;br /&gt;b7f63000      4K r----  /usr/lib/locale/en_HK.utf8/LC_MEASUREMENT&lt;br /&gt;b7f64000     28K r--s-  /usr/lib/gconv/gconv-modules.cache&lt;br /&gt;b7f6b000      4K r----  /usr/lib/locale/en_HK.utf8/LC_IDENTIFICATION&lt;br /&gt;b7f6c000      8K rw---    [ anon ]&lt;br /&gt;b7f6e000    100K r-x--  /lib/ld-2.4.so&lt;br /&gt;b7f87000      8K rw---  /lib/ld-2.4.so&lt;br /&gt;bfa1c000     88K rw---    [ stack ]&lt;br /&gt;ffffe000      4K -----    [ anon ]&lt;br /&gt;total     5528K&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;/proc/&lt;i&gt;pid&lt;/i&gt;&lt;/h4&gt;&lt;br /&gt;In &lt;code&gt;proc/&lt;i&gt;pid&lt;/i&gt;&lt;/code&gt; directory, it contains much information of a process.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;ahlam@oxygen:~/test/malloc$ ls -l /proc/4752&lt;br /&gt;total 0&lt;br /&gt;dr-xr-xr-x 2 ahlam ahlam 0 2007-04-19 20:17 attr&lt;br /&gt;-r-------- 1 ahlam ahlam 0 2007-04-19 20:17 auxv&lt;br /&gt;-r--r--r-- 1 ahlam ahlam 0 2007-04-19 19:57 cmdline&lt;br /&gt;-r--r--r-- 1 ahlam ahlam 0 2007-04-19 20:17 cpuset&lt;br /&gt;lrwxrwxrwx 1 ahlam ahlam 0 2007-04-19 18:20 cwd -&gt; /home/ahlam/test/malloc&lt;br /&gt;-r-------- 1 ahlam ahlam 0 2007-04-19 19:58 environ&lt;br /&gt;lrwxrwxrwx 1 ahlam ahlam 0 2007-04-19 20:17 exe -&gt; /bin/bash&lt;br /&gt;dr-x------ 2 ahlam ahlam 0 2007-04-19 19:57 fd&lt;br /&gt;-r--r--r-- 1 ahlam ahlam 0 2007-04-19 20:06 maps&lt;br /&gt;-rw------- 1 ahlam ahlam 0 2007-04-19 20:17 mem&lt;br /&gt;-r--r--r-- 1 ahlam ahlam 0 2007-04-19 20:17 mounts&lt;br /&gt;-r-------- 1 ahlam ahlam 0 2007-04-19 20:17 mountstats&lt;br /&gt;-rw-r--r-- 1 ahlam ahlam 0 2007-04-19 20:17 oom_adj&lt;br /&gt;-r--r--r-- 1 ahlam ahlam 0 2007-04-19 20:17 oom_score&lt;br /&gt;lrwxrwxrwx 1 ahlam ahlam 0 2007-04-19 20:17 root -&gt; /&lt;br /&gt;-rw------- 1 ahlam ahlam 0 2007-04-19 20:17 seccomp&lt;br /&gt;-r--r--r-- 1 ahlam ahlam 0 2007-04-19 20:17 smaps&lt;br /&gt;-r--r--r-- 1 ahlam ahlam 0 2007-04-19 19:57 stat&lt;br /&gt;-r--r--r-- 1 ahlam ahlam 0 2007-04-19 20:17 statm&lt;br /&gt;-r--r--r-- 1 ahlam ahlam 0 2007-04-19 19:57 status&lt;br /&gt;dr-xr-xr-x 3 ahlam ahlam 0 2007-04-19 20:17 task&lt;br /&gt;-r--r--r-- 1 ahlam ahlam 0 2007-04-19 20:17 wchan&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;For details, please &lt;code&gt;man proc&lt;/code&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-5364100914395747753?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=5364100914395747753' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/5364100914395747753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/5364100914395747753'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/04/know-more-about-process.html' title='Know more about a process'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1228030925443810185</id><published>2007-04-15T14:27:00.000+08:00</published><updated>2007-04-15T14:50:54.568+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Optimistic memory allocation strategy in Linux</title><content type='html'>If you know C programming language, you must know what is &lt;code&gt;malloc&lt;/code&gt;. &lt;code&gt;malloc&lt;/code&gt; is for dynamic memory allocation. In colleges, we learned that &lt;code&gt;malloc&lt;/code&gt; should return NULL in case of out-of-memory. However, it is not the case in Linux. By default, Linux uses optimistic memory allocation strategy. Under this strategy, Linux assumes there always exists free memory. The memory region returns by &lt;code&gt;malloc&lt;/code&gt; is not actually allocated until the process touches the memory region. This means the memory region returns by &lt;code&gt;malloc&lt;/code&gt; may not be available. In case of out-of-memory, the OOM Killer in Linux will pick up one or more process to kill. This sounds strange!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Reference:&lt;/span&gt;&lt;br /&gt;man malloc&lt;br /&gt;&lt;a href="http://linux-mm.org/OOM_Killer"&gt;http://linux-mm.org/OOM_Killer&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1228030925443810185?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1228030925443810185' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1228030925443810185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1228030925443810185'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/04/optimistic-memory-allocation-strategy.html' title='Optimistic memory allocation strategy in Linux'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1860608414140574371</id><published>2007-04-13T09:53:00.000+08:00</published><updated>2007-04-13T11:05:54.996+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Change the title of xterm</title><content type='html'>In most modern Linux distribution, the title of terminal follows the working directory. The mechanism behind this feature is not simple. You can even customize the title. Please note that, in this article, it is assumed to use xterm and bash.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_swgiJf5zUz0/Rh7oB64ouVI/AAAAAAAAABo/Ixad8nXamhw/s1600-h/terminal.gif"&gt;&lt;img style="cursor: pointer;" src="http://4.bp.blogspot.com/_swgiJf5zUz0/Rh7oB64ouVI/AAAAAAAAABo/Ixad8nXamhw/s320/terminal.gif" alt="" id="BLOGGER_PHOTO_ID_5052730951640594770" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;In xterm, the following escape sequence can change the title of terminal windows:&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;ESC]0;&lt;b&gt;title_string&lt;/b&gt;BEL&lt;/code&gt;&lt;/blockquote&gt;where &lt;code&gt;ESC&lt;/code&gt; and &lt;code&gt;BEL&lt;/code&gt; is 033  and 007 (in octal ASCII) respectively. For example, we can use the following &lt;code&gt;echo&lt;/code&gt; command to set the terminal title as "Hello World.":&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;echo -ne "\033]0;Hello World.\007"&lt;/code&gt;&lt;/blockquote&gt;&lt;br /&gt;However, if you issue the above command in your terminal, the title may not be changed. It is because the &lt;code&gt;PROMPT_COMMAND&lt;/code&gt; environment variable have already been defined for changing the terminal title. The value in &lt;code&gt;PROMPT_COMMAND&lt;/code&gt; environment variable will be executed as command prior to issuing each prompt. In my terminal, the value of &lt;code&gt;PROMPT_COMMAND&lt;/code&gt; is:&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"&lt;/code&gt;&lt;/blockquote&gt;&lt;br /&gt;In the above command, &lt;code&gt;${USER}&lt;/code&gt; and &lt;code&gt;${HOSTNAME}&lt;/code&gt; is the username and hostname respectively, while the &lt;code&gt;${PWD/$HOME/~}&lt;/code&gt; is the current working directory with $HOME abbreviated as &lt;code&gt;~&lt;/code&gt;. Therefore, in my terminal, the title will be changed to show username, hostname and current working directory, e.g.:&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;ahlam@oxygen: ~/download&lt;/code&gt;&lt;/blockquote&gt;&lt;br /&gt;To customize your terminal title, you should update the value of &lt;code&gt;PROMPT_COMMAND&lt;/code&gt;, e.g.:&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;export PROMPT_COMMAND='echo -ne "\033]0;Hello World.\007"'&lt;/code&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Reference:&lt;br /&gt;&lt;a href="http://www.faqs.org/docs/Linux-mini/Xterm-Title.html"&gt;How to change the title of an xterm&lt;/a&gt;&lt;br /&gt;man bash&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1860608414140574371?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1860608414140574371' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1860608414140574371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1860608414140574371'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/04/change-title-of-xterm.html' title='Change the title of xterm'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_swgiJf5zUz0/Rh7oB64ouVI/AAAAAAAAABo/Ixad8nXamhw/s72-c/terminal.gif' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1607695329268086738</id><published>2007-03-31T21:45:00.000+08:00</published><updated>2007-03-31T22:04:08.066+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Adobe Reader crashes with SCIM</title><content type='html'>I am using Ubuntu 6.10. Recently, I have installed Adobe Reader 7.0.9. However, Adobe Reader crashed at startup. In &lt;a href="http://ubuntuguide.org/wiki/Ubuntu:Edgy/AddOnApplications#How_to_install_PDF_Reader_.28Adobe_Reader.29_with_Plug-in_for_Mozilla_Firefox"&gt;ubuntuguide.org&lt;/a&gt; , it mentions Adobe Reader won't work with SCIM. Finally, I found the solution -- &lt;a href="http://www.scim-im.org/projects/scim_bridge"&gt;scim bridge&lt;/a&gt;. To solve the problem, install the scim-bridge package and edit the "acroread" script to insert the line "GTK_IM_MODULE=scim-bridge" at the beginning of the script, like:&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;GTK_IM_MODULE=scim-bridge&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;Then, Adobe Reader launches normally!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1607695329268086738?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1607695329268086738' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1607695329268086738'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1607695329268086738'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/03/adobe-reader-crashes-with-scim.html' title='Adobe Reader crashes with SCIM'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-2579670700766730025</id><published>2007-03-10T08:33:00.000+08:00</published><updated>2007-03-10T09:15:36.220+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Be careful with STL strings</title><content type='html'>Please refer to the following C++ code fragment:&lt;br /&gt;&lt;pre&gt;    char charArray[4]={'a','b','c',0,};&lt;br /&gt;    string str1(charArray);&lt;br /&gt;    string str2;&lt;br /&gt;    str2.append(charArray, 4);&lt;/pre&gt;Use the following lines to print out the contents of str1 and str2:&lt;br /&gt;&lt;pre&gt;    cout &lt;&lt; "str1 [" &lt;&lt; str1 &lt;&lt; ']' &lt;&lt; endl;&lt;br /&gt;    cout &lt;&lt; "str2 [" &lt;&lt; str2 &lt;&lt; ']' &lt;&lt; endl;&lt;/pre&gt;The output would be:&lt;br /&gt;&lt;pre&gt;str1 [abc]&lt;br /&gt;str2 [abc]&lt;/pre&gt;Two strings looks same. However, does str1 equal to str2?&lt;br /&gt;&lt;pre&gt;    cout &lt;&lt; (str1 == str2? "equal" : "not equal") &lt;&lt; endl;&lt;br /&gt;&lt;/pre&gt;The output:&lt;br /&gt;&lt;pre&gt;not equal&lt;br /&gt;&lt;/pre&gt;Why not!? Let's print out the size of the strings:&lt;br /&gt;&lt;pre&gt;    cout &lt;&lt; "str1 size = " &lt;&lt; str1.size() &lt;&lt; endl;&lt;br /&gt;    cout &lt;&lt; "str2 size = " &lt;&lt; str2.size() &lt;&lt; endl;&lt;/pre&gt;The output:&lt;br /&gt;&lt;pre&gt;str1 size = 3&lt;br /&gt;str2 size = 4&lt;/pre&gt;In short, we should be careful about the == operator of strings. It does not only compare the contents of strings, but it also compares the size of strings.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-2579670700766730025?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=2579670700766730025' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/2579670700766730025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/2579670700766730025'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/03/be-careful-with-stl-strings.html' title='Be careful with STL strings'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1696115231742696272</id><published>2007-03-03T15:54:00.000+08:00</published><updated>2007-03-04T10:25:55.934+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Does it really need to Lock?</title><content type='html'>In multi-threading environment, we always face the problem of race condition -- concurrent accessing sharing data among threads. To solve the problem, we can use locking primitives, e.g. mutex, to avoid concurrent accessing of sharing data. However, those locking primitives are expensive, since they involve system calls. In some cases, we can avoid using locks.&lt;br /&gt;&lt;br /&gt;&lt;span style=";font-family:arial;font-size:130%;"  &gt;Counting&lt;/span&gt;&lt;br /&gt;Suppose threads updating a &lt;span style="font-family:courier new;"&gt;count&lt;/span&gt; variable concurrently. To avoid race condition, I saw some implementation like:&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;"&gt;mutex.lock();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;count++;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;mutex.unlock();&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;Increment an integer just takes one CPU instruction, but locking and unlocking of mutex takes hundreds or thousands of CPU instructions. To avoid race condition, we can use atomic operations provided by CPU. Referring to /usr/include/asm-i386, there is implementation of atomic add:&lt;br /&gt;&lt;blockquote style="font-family: courier new;"&gt;static __inline__ void atomic_add(int i, atomic_t *v)&lt;br /&gt;{&lt;br /&gt;     __asm__ __volatile__(&lt;br /&gt;             LOCK_PREFIX "addl %1,%0"&lt;br /&gt;             :"=m" (v-&gt;counter)&lt;br /&gt;             :"ir" (i), "m" (v-&gt;counter));&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;In &lt;a href="http://apr.apache.org/"&gt;Apache Portable Runtime&lt;/a&gt; project, it provides a set of &lt;a href="http://apr.apache.org/docs/apr/1.2/group__apr__atomic.html"&gt;atomic operations&lt;/a&gt; for different platforms.&lt;br /&gt;&lt;br /&gt;&lt;span style=";font-family:arial;font-size:130%;"  &gt;Circular Buffers&lt;/span&gt;&lt;br /&gt;In general, without locking, a circular buffer cannot be thread-safe. However, under a restricted condition and implementation, there would be no race condition problem. In short, for a fixed size circular buffer, if there is exactly one reader and one writer, it does not need locking. It is because the reader only updates the read-pointer and the writer only updates the write-pointer. This issue have been discussed in &lt;a href="http://ddj.com/dept/cpp/184401814"&gt;http://ddj.com/dept/cpp/184401814&lt;/a&gt;. &lt;blockquote&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1696115231742696272?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1696115231742696272' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1696115231742696272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1696115231742696272'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/03/does-it-really-need-to-lock.html' title='Does it really need to Lock?'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-6366424267960072047</id><published>2007-02-04T10:35:00.000+08:00</published><updated>2007-02-04T12:08:48.147+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='networking'/><title type='text'>Is Port 25 blocked?</title><content type='html'>Port 25, default port of SMTP, is for E-mail transferring. To reduce SPAM, ISPs normally block this port, especially for those household DSL accounts. Therefore, people may think that it is impossible to setup E-mail server at home.&lt;br /&gt;I have experiences of using &lt;a href="http://www.hkbn.com.hk"&gt;HKBN&lt;/a&gt; and &lt;a href="http://www.netvigator.com"&gt;Netvigator&lt;/a&gt;, they are  not really block all port 25 traffics. They only block outgoing traffics, but not incoming traffic. To setup the E-mail server, we can use the "&lt;a href="http://www.jimmy.co.at/weblog/?p=53"&gt;smarthost&lt;/a&gt;" trick. &lt;span class="down" style="display: block;" id="formatbar_CreateLink" title="Link" onmouseover="ButtonHoverOn(this);" onmouseout="ButtonHoverOff(this);" onmouseup="" onmousedown="CheckFormatting(event);FormatbarButton('richeditorframe', this, 8);ButtonMouseDown(this);"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-6366424267960072047?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=6366424267960072047' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/6366424267960072047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/6366424267960072047'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/02/is-port-25-blocked.html' title='Is Port 25 blocked?'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-8278217190738271894</id><published>2007-01-27T21:50:00.000+08:00</published><updated>2007-01-28T10:19:22.740+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Stack Size of Threads</title><content type='html'>Several months ago, my boss assigned me to do performance tuning on several applications. One of them was a server application, which was for distributing data to clients. This application used a lot of threads, two threads per client -.-" It can support up to about 80 clients. If the number was over 80, the application generated a core dump. The core dump was due to out of memory. From &lt;span style="font-family: courier new;"&gt;top&lt;/span&gt;, I found the virtual memory size increases 4x MB for each newly connected client. It confused me. How could one client eat 4xMB?&lt;br /&gt;Finally, I found the answer -- stack size of a thread. In the Linux system, the default stack size of a thread  (in case of pthread library) is set to 20MB!&lt;br /&gt;To change the stack size of a thread,&lt;br /&gt;&lt;ol&gt;&lt;li&gt;use &lt;span style="font-family:courier new;"&gt;pthread_attr_setstacksize (&amp;attr, stacksize) &lt;/span&gt;to set the attribute during thread creation. For more details, you can refer to the following link: &lt;a href="http://www.llnl.gov/computing/tutorials/pthreads/#Stack"&gt;http://www.llnl.gov/computing/tutorials/pthreads/#Stack&lt;/a&gt;&lt;/li&gt;&lt;li&gt;use &lt;span style="font-family: courier new;"&gt;ulimit -s &lt;span style="font-style: italic;"&gt;nnnn&lt;/span&gt;&lt;/span&gt; command to change the default stack size of pthread, where &lt;span style="font-family: courier new; font-style: italic;"&gt;nnnn&lt;/span&gt; is the size in KBytes. (&lt;a href="http://kbase.redhat.com/faq/FAQ_43_8710.shtm"&gt;http://kbase.redhat.com/faq/FAQ_43_8710.shtm&lt;/a&gt;)&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-8278217190738271894?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=8278217190738271894' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/8278217190738271894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/8278217190738271894'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/01/stack-size-of-threads.html' title='Stack Size of Threads'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-7823271861194225644</id><published>2007-01-20T11:01:00.000+08:00</published><updated>2007-01-20T12:09:20.536+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><title type='text'>Find files by last modification time</title><content type='html'>"find" is a powerful Unix/Linux utility for searching files.  With the &lt;span style="font-family:courier new;"&gt;-mtime&lt;/span&gt; (or &lt;span style="font-family:courier new;"&gt;-mmin&lt;/span&gt;) options, "find" can search files which modified within a specific days (or minutes).  However, there is no option for "find" to search files modified after a point of time. To do this, you need to write a shell script:&lt;br /&gt;&lt;blockquote style="font-family: courier new;"&gt;#!/bin/sh&lt;br /&gt;touch -t "$1" /tmp/$$ \&lt;br /&gt;&amp;&amp;amp; find . -newer /tmp/$$ \&lt;br /&gt;&amp;&amp;amp; rm /tmp/$$&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;This script creates a temp file with a specific last modification time in &lt;span style="font-family:courier new;"&gt;/tmp&lt;/span&gt; directory  and uses the temp file's last modification time as a reference time point for "find" to search files newer than the specific time.  The &lt;span style="font-family:courier new;"&gt;-newer&lt;/span&gt; option of "find" is for searching files which are newer than a specific file. &lt;span style="font-family:courier new;"&gt;touch -t "$1" /tmp/$$&lt;/span&gt; creates a temp file with a specific last modified time using the &lt;span style="font-family:courier new;"&gt;-t&lt;/span&gt; option.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-7823271861194225644?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=7823271861194225644' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/7823271861194225644'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/7823271861194225644'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/01/find-files-by-last-modification-time.html' title='Find files by last modification time'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1450331653806687724</id><published>2007-01-14T16:37:00.000+08:00</published><updated>2007-01-14T16:53:58.334+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='networking'/><title type='text'>Speed up DNS Lookup in Linux</title><content type='html'>When I was first time to use Linux for web surfing, I found it was slower than MS Windows. Recently, I found the reason form the Internet. The difference is due to the DNS lookup speed. In Windows, it caches DNS lookup results but Linux doesn't. To improve the lookup speed in Linux, we can install &lt;a href="http://www.thekelleys.org.uk/dnsmasq/doc.html"&gt;dnsmasq&lt;/a&gt;, which is a light-weight DNS server for Linux.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1450331653806687724?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1450331653806687724' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1450331653806687724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1450331653806687724'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/01/speed-up-dns-lookup-in-linux.html' title='Speed up DNS Lookup in Linux'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-8267007268969958662</id><published>2007-01-01T13:24:00.000+08:00</published><updated>2007-01-02T08:56:39.086+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Bufferring Behaviour of stdout(Stardard Out)</title><content type='html'>Recently, I encounter a problem of capturing stdout of a program. The program is expected to run for a long time. When the output of the program is on the console, everything works fine. However, when the output of the program is redirected to a pipe or a file, the output is buffered for a long time. This means the output of the program is not appeared immediately. This behaviour is not desired. To illustrate the problem, I write the following simple program:&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;int main(int argc, char** argv)&lt;br /&gt;{&lt;br /&gt;    while (1)&lt;br /&gt;    {&lt;br /&gt;            sleep(1);&lt;br /&gt;            printf("hello!\n");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;The program prints "hello!" for every second. However, the output will be buffered if it is&lt;br /&gt;redirected to a pipe, like:&lt;br /&gt;a.out | tee tmp.log&lt;br /&gt;After some investigation, I found the behaviour is documented in setbuf(3) man page:&lt;br /&gt;&lt;blockquote&gt;The  three  types  of  buffering  available  are  unbuffered,  block buffered, and line buffered.  When an output stream is unbuffered, information appears on the destination file or  terminal  as  soon  as written; when it is block buffered many characters are saved up and written as a block; when it is line buffered characters are saved up until a  newline  is  output or  input is read from any stream attached to a terminal device (typically stdin).... Normally all files are block buffered.  When the first I/O operation occurs on a file, malloc(3) is called, and a buffer is obtained.  If a stream refers to a  terminal  (as  stdout normally does) it is line buffered.  The standard error stream stderr is always unbuffered by default....&lt;/blockquote&gt;&lt;br /&gt;There are two ways to solve the problem. First, call &lt;span style="font-size:100%;"&gt;fflush(stdout)&lt;/span&gt; after &lt;span style=";font-family:courier new;font-size:100%;"  &gt;printf.&lt;/span&gt;&lt;br /&gt;Second, call &lt;span style="font-family:courier new;"&gt;setlinebuf(stdout)&lt;/span&gt; at the startup of the program.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-8267007268969958662?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=8267007268969958662' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/8267007268969958662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/8267007268969958662'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2007/01/recently-i-encounter-problem-of.html' title='Bufferring Behaviour of stdout(Stardard Out)'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-8798303011681862035</id><published>2006-12-26T10:05:00.000+08:00</published><updated>2006-12-26T10:19:51.381+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='security'/><title type='text'>A Strange ICQ Message</title><content type='html'>Today, I received a very strange  ICQ message from one of my friend:&lt;br /&gt;&lt;blockquote style="font-family: courier new;"&gt;Hi, you've just received a postcard.&lt;br /&gt;&lt;br /&gt;To view the postcard click this link or copy it to your browser's address bar.&lt;br /&gt;http://cards.vertionpilinhertunfendsa.com/1/show.xml?id=201e624becfd36e0b7663089da805de0&lt;br /&gt;&lt;br /&gt;The postcard will be kept for 10 weeks.&lt;/blockquote&gt;The link in the message points to an executable file named "postcard_flash.exe". Why does a postcard need to be executable? It most likely is a virus or a worm. From the Internet, I found some information about this kind of virus:&lt;br /&gt;&lt;a href="http://www.sophos.com/security/analyses/w32mydoomal.html"&gt;http://www.sophos.com/security/analyses/w32mydoomal.html&lt;/a&gt;&lt;br /&gt;A very "clever" worm which spreads via email and ICQ messages. The worm tries to disable the firewall, as well as anti-virus program. Moreover, the worm changes the HOST file to prevent the compromised computer connecting to anti-virus and security web sites.... So what! I am using Linux.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-8798303011681862035?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=8798303011681862035' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/8798303011681862035'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/8798303011681862035'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/12/strange-icq-message.html' title='A Strange ICQ Message'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1413897101291942089</id><published>2006-12-21T21:34:00.000+08:00</published><updated>2006-12-24T20:53:38.244+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>C Macro Tricks</title><content type='html'>If you know C programming, you should know C macro as well. Macro is very powerful. However, it also makes the code difficult to read, especially macro with multi-level expansion. In complication of source code, the macro expansion is handled by "&lt;a href="http://en.wikipedia.org/wiki/C_preprocessor"&gt;C Preprocessor&lt;/a&gt;". To do trouble-shooting on macro expansion, we can use the "-E" option in gcc. The "-E" option tells the compiler to stop after "C Preporcessor". With "-E" option the output file of gcc will be a text file containing the source code with all macro expanded and #include files merged.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1413897101291942089?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1413897101291942089' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1413897101291942089'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1413897101291942089'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/12/c-macro-tricks.html' title='C Macro Tricks'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1010450472006788082</id><published>2006-12-14T22:03:00.000+08:00</published><updated>2006-12-14T22:37:47.326+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>gdb stops at SIGPIPE</title><content type='html'>By default, gdb captures SIGPIPE of a process and pauses it. However, some program ignores SIGPIPE. So, the default behavour of gdb is not desired when debugging those program. To avoid gdb stopping in SIGPIPE, use the folloing command in gdb:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;blockquote&gt;handle SIGPIPE nostop noprint pass&lt;/blockquote&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1010450472006788082?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1010450472006788082' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1010450472006788082'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1010450472006788082'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/12/gdb-ignore-sigpipe.html' title='gdb stops at SIGPIPE'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-4159359951214384112</id><published>2006-12-09T11:50:00.000+08:00</published><updated>2006-12-09T13:59:24.820+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='solaris'/><title type='text'>Installing Solaris 10 x86 in VMWare</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_swgiJf5zUz0/RXpQOELrLTI/AAAAAAAAAAM/ma5QCRLa2E0/s1600-h/solaris_in_vm.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_swgiJf5zUz0/RXpQOELrLTI/AAAAAAAAAAM/ma5QCRLa2E0/s320/solaris_in_vm.jpg" alt="" id="BLOGGER_PHOTO_ID_5006402138346827058" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Yesterday, I tried to install Solaris 10 x86 in  VMWare virtual machine. Overall, the installation was quite smooth. I faced a little problem in the harddisk partitioning stage. I selected "auto-layout" but failed at first time. Then, I went back one step and try "auto-layout" again and it worked for second time. Maybe there is a bug in the installation.&lt;br /&gt;After installation, the resolution of X window was low. I had to run "/usr/X11/bin/xorgconfig" to config the resolution.&lt;br /&gt;Next, I installed vmware-tool for Solaris. After installed the vmware-tool the NIC is changed from pcn0 to vmxnet0. So, I need to copy the hostname.pcn0 to hostname.vmxnet0 and dhcp.pcn0 to dhcp.vmxnet0.&lt;br /&gt;Then, I tried to run mozilla to check the Internet connection. Unluckly, the browser always report unknown host. I have verified the "/etc/resolve.conf" for DNS setting. It is correct. I also tried to use "dig www.google.com" to resolve the IP address successfully. Finally, from forum of Internet, we had to modify the "/etc/nsswitch.conf" as well.... -.-"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-4159359951214384112?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=4159359951214384112' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4159359951214384112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4159359951214384112'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/12/installing-solaris-10-x86-in-vmware.html' title='Installing Solaris 10 x86 in VMWare'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_swgiJf5zUz0/RXpQOELrLTI/AAAAAAAAAAM/ma5QCRLa2E0/s72-c/solaris_in_vm.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-3377026164412986121</id><published>2006-12-08T14:09:00.000+08:00</published><updated>2006-12-08T15:05:15.672+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='networking'/><title type='text'>Linux VPN Client for Cisco VPN Router</title><content type='html'>The desktop of my office is in private network behind a firewall. If I need to access the desktop of my office, I need to use VPN by connecting the Cisco VPN Router in my office. It is not a trivial task to connecting VPN router in Linux platform, and there are seems several ways:&lt;br /&gt;&lt;ol&gt;&lt;li&gt; Use the official &lt;a href="http://www.cisco.com/en/US/products/sw/secursw/ps2308/products_user_guide_book09186a00802aa59f.html"&gt;Cisco VPN Client for Linux&lt;/a&gt;. During the installation, it needs the kernel headers for module complication. It should work in most cases. However, this software package is not freely available and open source. &lt;/li&gt;&lt;li&gt; &lt;a href="http://http//www.unix-ag.uni-kl.de/%7Emassar/vpnc/"&gt;VPNC&lt;/a&gt; is an open source VPNC client target for cisco3000 VPN Concentrator. It works well for me. However, some features are not supported, e.g. re-keying, digital certificate authentication....&lt;/li&gt;&lt;li&gt; &lt;a href="http://www.openswan.org/"&gt;Openswan&lt;/a&gt; is an implementation of IPsec for Linux. It is not only a VPN client, it can act as VPN router. I found some &lt;a href="http://www.openswan.org/docs/local/README.XAUTHclient"&gt;document&lt;/a&gt; about how to use Openswan for connecting Cisco VPN router. However, it fails in my Ubuntu box :&lt;.&lt;/li&gt;&lt;/ol&gt;There is some &lt;a href="http://searchwindowssecurity.techtarget.com/tip/0,289483,sid45_gci1199124,00.html"&gt;web pages&lt;/a&gt; mentions that the XAuth of Cisco VPN router is non-standard. No wonder open source software packages don't support it well.&lt;br /&gt;&lt;br /&gt;    &lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-3377026164412986121?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=3377026164412986121' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3377026164412986121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3377026164412986121'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/12/linux-vpn-client-for-cisco-vpn-router.html' title='Linux VPN Client for Cisco VPN Router'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-9071104788054167030</id><published>2006-12-08T13:39:00.000+08:00</published><updated>2006-12-08T14:04:52.467+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='www'/><title type='text'>Free Advertising for Your Blog</title><content type='html'>Here is some suggestion for advertising your blog. First you can register your blog to some blog directories:&lt;a href="http://www.blogcatalog.com/"&gt;&lt;br /&gt;&lt;/a&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.blogcatalog.com/"&gt;http://www.blogcatalog.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog-you.com/"&gt;http://blog-you.com/&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;Second, you can reply posts in some popular newsgroups and forums. Include your blog's info in the signature of your replies.&lt;br /&gt;Third, ask your friends to add the link of your blog in their homepage or blog.&lt;br /&gt;The more web pages pointing to your blog, the higher ranking you can get in Google's search engine. To know the ranking of your homepage for some specific keywords in search engines, you can visit &lt;a href="http://www.googlerankings.com/index.php"&gt;http://www.googlerankings.com/index.php&lt;/a&gt;. Now, it supports Google, MSN Search, Yahoo and Ask Search.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-9071104788054167030?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=9071104788054167030' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/9071104788054167030'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/9071104788054167030'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/12/free-advertising-for-your-blog.html' title='Free Advertising for Your Blog'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-7487472762526554594</id><published>2006-12-01T15:57:00.000+08:00</published><updated>2006-12-01T16:03:20.375+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Ubuntu with Compiz</title><content type='html'>&lt;a href="http://en.wikipedia.org/wiki/Compiz"&gt;Compiz&lt;/a&gt; is a window manager with amusing visual effects. You can find some screen captures in &lt;a href="http://www.youtube.com/results?search_query=compiz&amp;amp;search=Search"&gt;YouTube&lt;/a&gt;. Yesterday, I installed Compiz in my Ubuntu (Edgy) Linux and it works great. The following the screen capture of my desktop:&lt;br /&gt;&lt;br /&gt;&lt;object height="350" width="425"&gt; &lt;param name="movie" value="http://www.youtube.com/v/-yEm559NyhI"&gt;  &lt;embed src="http://www.youtube.com/v/-yEm559NyhI" type="application/x-shockwave-flash" height="350" width="425"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;The following is the How-to about installing Compiz in Ubuntu:&lt;br /&gt;&lt;a href="http://gandalfn.wordpress.com/howto/howto-compiz-aiglx-on-edgy/"&gt;http://gandalfn.wordpress.com/howto/howto-compiz-aiglx-on-edgy/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-7487472762526554594?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=7487472762526554594' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/7487472762526554594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/7487472762526554594'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/12/ubuntu-with-compiz.html' title='Ubuntu with Compiz'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-3170019487384173285</id><published>2006-11-26T10:12:00.000+08:00</published><updated>2006-11-26T12:22:59.917+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='multimedia'/><title type='text'>Rename a JPG File to Photo Taking Time</title><content type='html'>If you use DC to take photos, the file names are in form of a prefix following by a sequence number. This form of file name is meaningless and not convenient for looking up. Recently, I found a tools called &lt;a href="http://www.sentex.net/%7Emwandel/jhead/"&gt;jhead&lt;/a&gt; which can rename JPG files to their photo taking time in  a batch. To do the batch renaming, just issue a single command:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;jhead -n%Y%m%d-%H%M%S *.jpg&lt;/span&gt;&lt;br /&gt;jhead is more than a file rename util. It is a exif Jpeg header and thumbnail manipulator utitliy. Please visit jhead's web site for details: &lt;a href="http://www.sentex.net/%7Emwandel/jhead/"&gt;http://www.sentex.net/~mwandel/jhead/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-3170019487384173285?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=3170019487384173285' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3170019487384173285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3170019487384173285'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/11/rename-jpg-file-to-photo-taking-time.html' title='Rename a JPG File to Photo Taking Time'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-2002034482039486897</id><published>2006-11-24T14:34:00.000+08:00</published><updated>2006-11-25T11:29:22.575+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>STL list size() method is slow</title><content type='html'>In STL list, the size() method is &lt;span style="font-style: italic;"&gt;o(n)&lt;/span&gt;, where  &lt;span style="font-style: italic;"&gt;n&lt;/span&gt; is number of elements in the list. The implementation of size() is by traversing the linked list and counting the nodes one by one. So, it sounds stupid.&lt;br /&gt;I have written a simple program to test the performance of size() method in STL list and STL vector. For a STL list with 10M integers, it takes 0.17 sec. to get the size. However, for a STL vector with 10M integers, it takes 0.4 micro sec to get the size() in same machine.&lt;br /&gt;There are some suggestions:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Use vector instead of list.&lt;/li&gt;&lt;li&gt;If the application need to check whether the list is empty or not, uses "&lt;span style="font-family:courier new;"&gt;list.emtpy()&lt;/span&gt;" instead of "&lt;span style="font-family:courier new;"&gt;list.size() != 0&lt;/span&gt;".&lt;br /&gt;&lt;/li&gt;&lt;li&gt;use an extra counter variable to counting the size of a list.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-2002034482039486897?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=2002034482039486897' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/2002034482039486897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/2002034482039486897'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/11/stl-list-size-method-is-slow.html' title='STL list size() method is slow'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-4341911514992370785</id><published>2006-11-19T15:23:00.000+08:00</published><updated>2006-11-19T16:22:01.499+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>VMWare Server with ALSA DMix</title><content type='html'>In Linux, the sound-card drivers normally do not support concurrent access. This means when you playing MP3, your instant-chat program (e.g. gaim) will be mute. To solve this problem, there are some projects -- ALSA DMix, ESD, ARTSD, JACK.... However, most of them are not compatible each other and the applications needs to use the API provided by the specific project.&lt;br /&gt;&lt;br /&gt;In my Ubuntu desktop, I use ALSA DMix with ESD approach. Most applications should support ALSA or ESD. However, VMWare support neither of them. VMWare only use native /dev/dsp device for sounding. After some searching on the web, we can use the LD_PRELOAD libossa.so trick.&lt;br /&gt;&lt;br /&gt;After half day of try-and-error, the following is the summary of how to make VMWare work with ALSA:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;make sure you installed the package "olsa-oss".&lt;/li&gt;&lt;li&gt;add suid bit to /usr/lib/libaoss.so by command &lt;span style="font-family:courier new;"&gt;chmod +s /usr/lib/libaoss.so&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;rename the /usr/lib/vmware/bin/vmware-vmx to vmware-vmx-real&lt;/li&gt;&lt;li&gt;create a shell script /usr/lib/vmware/bin/vmware-vmx with the following contents&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:courier new;"&gt;#!/bin/sh&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;LD_PRELOAD=libaoss.so exec /usr/lib/vmware/bin/vmware-vmx-real $@&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;make sure the shell script is executable (i.e. &lt;span style="font-family:courier new;"&gt;chmod a+x /usr/lib/vmware/bin/vmware-vmx-real&lt;/span&gt;)&lt;/li&gt;&lt;li&gt;If your guest OS's disk image file is "single growable virtual disk" type with size large than 2G, you should use the &lt;span style="font-family:courier new;"&gt;vmware-vdiskmanager&lt;/span&gt; to split it into several files. Otherwise, you will encounter the problem of "File too large".&lt;/li&gt;&lt;/ul&gt;&lt;span style="FONT-STYLE: italic"&gt;Related Link:&lt;/span&gt;&lt;br /&gt;&lt;a style="FONT-STYLE: italic" href="http://www.vmware.com/community/message.jspa?messageID=491195"&gt;A Post about VMWare works with ALSA&lt;/a&gt;&lt;br /&gt;&lt;a href="http://alsa.opensrc.org/index.php?page=DmixPlugin"&gt;ALSA DMix&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-4341911514992370785?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=4341911514992370785' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4341911514992370785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4341911514992370785'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/11/vmware-server-with-alsa-dmix.html' title='VMWare Server with ALSA DMix'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-4677468148874418560</id><published>2006-11-10T13:46:00.000+08:00</published><updated>2006-11-19T13:53:23.303+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Switch To Ubuntu</title><content type='html'>I have been used Linux as my primary desktop OS since 2001. At that time, I used Mandrake because it was easy to install. Then I switched to Debain because of its good package management and package update. Today, I decided to switch to Ubuntu.&lt;br /&gt;&lt;br /&gt;Ubuntu is based on Debian's package management and adds user-friendly installation. No wonder Ubuntu is the most popular Linux distribution (&lt;a href="http://distrowatch.com/"&gt;http://distrowatch.com&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;Today, I tried to install Ubuntu and don't encounter any difficulty. It can auto detect and configure all my hardware (sound card, video card, network card....). So, everything works properly!&lt;br /&gt;&lt;br /&gt;One year ago, I have tried to install Ubuntu and I found it was not mature. So, I remained to use Debian. Now, Ubuntu 6.10 is much better. I love it!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-4677468148874418560?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=4677468148874418560' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4677468148874418560'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4677468148874418560'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/11/switch-to-ubuntu.html' title='Switch To Ubuntu'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-299833801206821094</id><published>2006-01-07T13:47:00.000+08:00</published><updated>2006-11-19T13:48:42.092+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='networking'/><title type='text'>Does MTU matter?</title><content type='html'>Recently, I have changed my ISP to &lt;a href="http://www.hkbn.com.hk/"&gt;HKBN&lt;/a&gt;. I chose the plan BB10 which provide 10Mb upload and download speed. This is much better than ADSL. For such high bandwidth, I want to use my NSLU2 Linux box to setup a web server at my home.     &lt;p&gt; However, there is some problems. I found that not every machine can access  my web server. Ellen using Pacific Supernet cannot access the web server.  Besides, a friend of mine using Netvigator faces the same problem.  However, the W3C's HTML validate can access my web server to validate  my HTML files. Moreover, my company can also access the server.   &lt;/p&gt;&lt;p&gt; This is really strange. Today, I try to tackle the problem. I tried to set the server in DMZ at my router but fail. Then, I look for other  setting in the router's configuration. I find the item "MTU". MTU stands for "maximum transmission unit". Currently setting is 1500 which is the maximum allowed value. I try to change the value smaller to 1400. It works! However, I want to ask, "Does MTU matter?".    &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-299833801206821094?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=299833801206821094' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/299833801206821094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/299833801206821094'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/01/does-mtu-matter.html' title='Does MTU matter?'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-2591466964136496894</id><published>2005-12-29T13:46:00.000+08:00</published><updated>2006-11-19T13:46:38.643+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Install Ubuntu Linux Cont'</title><content type='html'>&lt;p&gt;Today, I go to fine tune the Ubuntu Linux in my desktop. One disadvantage of Ubuntu comparing with Debian is Ubuntu supports less packages officially. For example, the SCIM, a Input Method modules support many languages, is not  included in Ubuntu.     &lt;/p&gt;&lt;p&gt;To install the SCIM, I includes the "Universe" packages pool in my Ubuntu and install the SCIM. The "Universe" pool contains some extra packages which is not officially support by Ubuntu team. After install the SCIM, I try to run the "Setup" of SCIM. However it can't run properly -- seg. fault. As a Debian user, this problem becomes the weak points of Ubuntu. In Debian, it officially support much more packages than Ubuntu. I think Ubuntu need to put more effort to  support more packages.  &lt;/p&gt;&lt;p&gt;Finally, I decide to install a Debian on my desktop and give up the  fine tuning the Ubuntu. The installation of Debian is more complicated than Ubuntu. Fortunately, I am a experienced Debian User.   &lt;/p&gt;&lt;p&gt;After installation complete, the XWindow can start correctly. However, my  sound card doesn't work. To solve this, I need to install ALSA package via the "aptitude" (Note: aptitude is a Debian package manager). Moreover, the middle  button of my mouse doesn't work and this is similar to the case of Ubuntu.  The solution was mentioned yesterday's BLOG entry.  Then, I install the SCIM and other Chinese related packages. The SCIM works properly!    &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-2591466964136496894?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=2591466964136496894' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/2591466964136496894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/2591466964136496894'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/12/install-ubuntu-linux-cont.html' title='Install Ubuntu Linux Cont&apos;'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-4720309086348675492</id><published>2005-12-28T13:44:00.000+08:00</published><updated>2006-11-19T13:45:33.874+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Install Ubuntu Linux</title><content type='html'>According to &lt;a href="http://distrowatch.com/"&gt;DistroWatch&lt;/a&gt;, &lt;a href="http://www.ubuntulinux.org/"&gt;Ubuntu Linux&lt;/a&gt; is the most popular Linux distribution. Today, I want to experience how good it is.   &lt;p&gt;The installation is quite simple and straight forward. It can detect all my hardware and can run up XWindow without any manual settings. My sound card and CD RW also works properly.  &lt;/p&gt;&lt;p&gt;There is one problem on my mouse. The middle key doesn't works. With hours  of investigation, I find the solution. The problem is due to the "psmouse" kernel module. It detects my mouse incorrectly. To solve the problem,  the parameter "proto=imps" should be used while loading the kernel module. So, I create a file "psmouse" in "/etc/modprode.d" with the following contents: &lt;/p&gt;&lt;pre&gt;options psmouse proto=imps &lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-4720309086348675492?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=4720309086348675492' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4720309086348675492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4720309086348675492'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/12/install-ubuntu-linux.html' title='Install Ubuntu Linux'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-4649101717881759593</id><published>2005-12-14T13:43:00.000+08:00</published><updated>2006-11-19T13:43:49.670+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>CSV File Format</title><content type='html'>&lt;p&gt; CSV stands for &lt;emp&gt;Comma Separated Values&lt;/emp&gt;. It is a common file format for storing tabular data, e.g. spread sheet data.  The file format of CSV is simple -- a text file, values are separated by comma (,) and rows are separated by newline. However, there is still some tricky in the format.   &lt;/p&gt;&lt;p&gt; The tuck point is how to escape the comma in the values. If a value contains commas, the value should be quoted with double-quote ("). e.g.: &lt;/p&gt;&lt;pre&gt;value one,"value two with ',' inside",value three&lt;br /&gt;&lt;/pre&gt; If a value contains a double-quote, the value should be quoted with double-quote and the double-quote in the value should be escaped with another double-quote. e.g.: &lt;pre&gt;value one,"value two with '""' inside",value three&lt;br /&gt;&lt;/pre&gt; The specification of the CSV is described in &lt;a href="http://www.ietf.org/rfc/rfc4180.txt"&gt;RFC4180&lt;/a&gt;.  &lt;p&gt; Even there is an RFC standard for CSV format, there are some deviation standard exists.  In some applications, the comma and double-quote is escaped by a back-slash (\).  Moreover, the character encoding is not stored in the file format and causes ambiguity. So, it is not trivial while using this format.   &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-4649101717881759593?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=4649101717881759593' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4649101717881759593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4649101717881759593'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/12/csv-file-format.html' title='CSV File Format'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-8467740063064105727</id><published>2005-11-24T13:39:00.000+08:00</published><updated>2006-11-19T13:41:39.813+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Missing Samba after Upgrade Packages</title><content type='html'>My Old PC is a Debian Linux box. I have not upgraded the packages for a long time. Therefore, yesterday, I run Aptitude to do a mass updates. Today, I find the Samba is removed after the mass updates.   &lt;p&gt; I run Aptitude to figure out the reason. I found the Samba has some broken dependency -- libdb4.1. Then, I search the libdb4.1 on the Web. In the unstable branch of Debian, it only supports AMD64 Architecture. Oh! Some packages in Debian is moving from unstable to stable branch.  &lt;/p&gt;&lt;p&gt; So, I edit the "/etc/apt/sources.list" to add the stable repository: &lt;/p&gt;&lt;pre&gt;deb http://ftp.hk.debian.org/debian/ stable main non-free contrib&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; Then run Aptitude and update the package list. The broken dependency problem solve and Samba can be installed.   &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-8467740063064105727?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=8467740063064105727' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/8467740063064105727'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/8467740063064105727'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/11/missing-samba-after-upgrade-packages.html' title='Missing Samba after Upgrade Packages'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-5370507033380801736</id><published>2005-11-23T13:38:00.000+08:00</published><updated>2006-11-19T13:39:32.323+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='misc'/><title type='text'>Free Virtual Machine -- QEMU</title><content type='html'>Long time ago, I have tried QEMU. I run QEMU in Debian and the guest OS is Win2000.  It worked but it was very slow.  Recently, I visit the site of QEMU and there is a QEMU Accelerator Module.  According to the site, with the accelerator, QEMU's performance is comparable to commercial products.  &lt;p&gt; I want to try QEMU in Windows XP. However, the accelerator for windows is alpha version. Anyway, I still want to try to download and run it on my Win XP.  The guest OS is the sample Linux which can be download the QEMU's website.  It crashes in LILO. Too bad!!!! After that, I try to run QEMU without the accelerator. It works fine. I think the accelerator for windows need to be improved.  &lt;/p&gt;&lt;p&gt; Then, I try another accelerator module -- qvm86. This is a open source accelerator module. This module is even worse. It crashes my WinXP.  &lt;/p&gt;&lt;p class="note"&gt; Related Links:&lt;br /&gt;&lt;a href="http://fabrice.bellard.free.fr/qemu/"&gt;Offical site of QEMU&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.h7.dion.ne.jp/%7Eqemu-win/"&gt;QEMU porting on Windows&lt;/a&gt;&lt;br /&gt;&lt;a href="http://savannah.nongnu.org/projects/qvm86/"&gt;QVM86&lt;/a&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-5370507033380801736?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=5370507033380801736' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/5370507033380801736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/5370507033380801736'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/11/free-virtual-machine-qemu.html' title='Free Virtual Machine -- QEMU'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-3523577812596963882</id><published>2005-11-20T13:35:00.000+08:00</published><updated>2006-11-19T13:39:55.145+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='misc'/><title type='text'>Trojan Found</title><content type='html'>Two days ago, my sister reported to me that her computer had torjan.  On one hand, IE has many many security bugs. On the other hand, she have not done Windows Update for a long long time. I guess the trojan was planted by visiting some &lt;emp&gt;bad&lt;/emp&gt; web-site. Actually, I have told her don't use IE, use Firefox!   &lt;p&gt; The trojan was found by AVG virus scanner. Actually, there are two trojans found: PSW.Generic.BWM and PSW.Generic.DAP. I search them in google, and nothing related found. The infected file are "WINDOWS\SYSTEM32\msd.dll" and "WINDOWS\SYSTEM32\roddll.dll".  &lt;/p&gt;&lt;p&gt; For the filename "roddll.dll", I find some information on the Web.  There is a trojan named "Troj/Ragrok-A". This trojan creates "WINDOWS\rundll132.exe"  and the "roddll.dll" file. Moreover, it also creates a registry entry to execute the  "rundll132.exe" in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run. So, it is not  difficult to remove.  &lt;/p&gt;&lt;p&gt; For the "msd.dll", there is not much information find. Anyway, I inspect the  HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run in the registry, I find a suspect entry: "WINDOWS\system\rundll32.exe". I search on Google by key words "rundll32.exe" and "trojan". I find that rundll32.exe file is located in the c:\windows\System32 folder. In other cases, rundll32.exe is a virus, spyware, trojan or worm! Then, I remove the  entry in the registry, remove the "rundll32.exe" in "WINDOWS\SYSTEM", as well as the "msd.dll". Then, reboot. Everything works fine! The AGV scanner doesn't find any trojan.  &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-3523577812596963882?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=3523577812596963882' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3523577812596963882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3523577812596963882'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/11/trojan-found.html' title='Trojan Found'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1410715039551916877</id><published>2005-11-18T13:33:00.000+08:00</published><updated>2006-11-19T13:35:15.703+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='www'/><title type='text'>Obfuscate the Spammer's Robot</title><content type='html'>Most email users should have experience of receiving junk email. For me, my HongKong.com account, it receives around 100 junk email each day. This  wastes our time to filter the email and makes us feel annoying.     &lt;p&gt; Do you know how a spammer get your email addresses? Actually, your email addresses may already be put on the Web which can be accessed by the public. For example, in web-sites of many companies, they put contact lists containing email addresses of its staff.  spammers use a program, called robot, to automatically retrieve email addresses on the Web.  The spammers' robots &lt;emp&gt;move&lt;/emp&gt; on the Web and try to get the email addresses. So, don't put your email addresses publicly.  &lt;/p&gt;&lt;p&gt; However, sometimes you can't avoid it. So, it is suggested to post your email addresses on the Web in a obfuscated form. For example: &lt;/p&gt;&lt;pre&gt;john [at] google [dot] com&lt;br /&gt;&lt;/pre&gt; The robot is a very simple program which can only recognize the email addresses in the form of "xxx@xxxx.xxx". Once the email address is transformed, the robot can't recognize it, but human can.  However, it is not user-friendly. I suggest to use JavaScript to transform the the obfuscated email addresses back when mouse is over the email addresses.  Here is a real example in my homepage: &lt;a href="http://ahlam.no-ip.org/contact.html"&gt;Contact&lt;/a&gt;. Such that, someone can copy and past the email address directly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1410715039551916877?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1410715039551916877' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1410715039551916877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1410715039551916877'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/11/obfuscate-spammers-robot.html' title='Obfuscate the Spammer&apos;s Robot'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-6948254394762369355</id><published>2005-11-16T13:31:00.000+08:00</published><updated>2006-11-19T13:33:11.922+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Get the Date of Tomorrow/Yesterday in Shell Script</title><content type='html'>In shell script, we may need to get the date of tomorrow/yesterday. If you use GNU version of "date", it is a piece of cake: &lt;pre&gt;date -d tomorrow +%Y-%m-%d&lt;br /&gt;&lt;/pre&gt;    The above command will display the date of tomorrow in "yyyy-mm-dd" format. Similarly, to find the date of yesterday: &lt;pre&gt;date -d yesterday +%Y-%m-%d&lt;br /&gt;&lt;/pre&gt; The power of the GNU date command is out of my imagination, see the following examples: &lt;pre&gt;date -d "2 days ago"&lt;br /&gt;date -d "3 weeks ago"&lt;br /&gt;date -d "1 month ago"&lt;br /&gt;date -d "3 days"&lt;br /&gt;date -d "4 weeks"&lt;br /&gt;date -d "2 month"&lt;br /&gt;date -d "2 month 1 week"&lt;br /&gt;&lt;/pre&gt; However, if your "date" is non-GNU version (e.g. in Solaris), it doesn't support "-d" option. Then, there seems no simple command can do this. You may need to write Perl script or use other more powerful programming/scripting language to achieve same results.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-6948254394762369355?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=6948254394762369355' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/6948254394762369355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/6948254394762369355'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/11/get-date-of-tomorrowyesterday-in-shell.html' title='Get the Date of Tomorrow/Yesterday in Shell Script'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-3044629000814166017</id><published>2005-11-15T13:30:00.000+08:00</published><updated>2006-11-19T13:32:48.173+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Power of "find"</title><content type='html'>"find" is a command line utility. Its basic usage is to find some files. e.g. &lt;pre&gt;find . -name '*.html'&lt;br /&gt;&lt;/pre&gt; The above example is to find all HTML files under current directory. &lt;p&gt;  While building a homepage, it is common to change HTML and graphic files to 0644 permission. We can use the "-exec" option of find to execute the "chmod"; command to  change the permission of the files, e.g: &lt;/p&gt;&lt;pre&gt;find . \( -name '*.html' -o -name '*.png' -o -name '*.jpg' \) -exec chmod 0644 {} \;&lt;br /&gt;&lt;/pre&gt; The parameters after "-exec" is the command to be executed. In the command, "{}" is replaced by the found file. The "\;" is the terminator of the command of  "-exec".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-3044629000814166017?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=3044629000814166017' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3044629000814166017'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3044629000814166017'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/11/power-of-find.html' title='Power of &quot;find&quot;'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-5957997596898604206</id><published>2005-11-14T13:28:00.000+08:00</published><updated>2006-11-19T13:33:30.372+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='www'/><title type='text'>Comments Submission</title><content type='html'>I continued to my Blog development. In the comments text area of comments submission, my original implementation did NOT allow any HTML tag. It was mainly due to security reasons. However, this made the text of comments looks dull. I think it is better to allow some simple formatting tag e.g. &amp;lt;p&amp;gt;, &amp;lt;b&amp;gt;, &amp;lt;i&amp;gt;....   &lt;p&gt; After did some survey on the web, I found the most popular technology is BBCode.  BBCode defines a set of tags in form of "[xxx]" which will be converted to HTML tags. For example, "[b]bold text[/b]" is converted to "&amp;lt;b&amp;gt;bold text&amp;lt;/b&amp;gt;".  There are several free BBCode parsers available. It is convenient to deploy this technology.  &lt;/p&gt;&lt;p&gt; One disadvantage of BBCode is not user-friendly. Users need to learn a new set of code. I thinks it is better to have a WYSIWYG editor. Unfortunately, I cannot find any web-based WYSIWYG editor for BBCode.   &lt;/p&gt;&lt;p&gt; On the other hand, I found some open source web-based &lt;a href="http://www.geniisoft.com/showcase.nsf/WebEditors"&gt;WYSIWYG HTML editors&lt;/a&gt;.  It is great! I have tried the Cross-Browser Rich Text Editor and it works well in both Firefox and IE.  &lt;/p&gt;&lt;p&gt; However, it is not secure to accept all HTML tags. On server side, it should filter out some dangerous tags, e.g. &lt;javascript&gt;, .... There already exist some HTML filters. One of them is &lt;a href="http://pixel-apes.com/safehtml/"&gt;safehtml&lt;/a&gt;.  Finally, I decided to use the WYSIWYG HTML editor plus HTML filter.  &lt;/javascript&gt;&lt;/p&gt;&lt;p&gt; &lt;emp&gt;&lt;br /&gt;&lt;/emp&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-5957997596898604206?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=5957997596898604206' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/5957997596898604206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/5957997596898604206'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/11/comments-submission.html' title='Comments Submission'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1256658044816953442</id><published>2005-10-31T13:26:00.000+08:00</published><updated>2006-11-19T13:26:59.831+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Java Generics</title><content type='html'>J2SE 5.0 have been released for a long time. However, I didn't have time to study it.  Today, I spend some time to have a look of it's new features. One new feature introduced in J2SE 5.0 is generics.    &lt;p&gt; In Wikipedia, the term &lt;emp&gt;generics&lt;/emp&gt; is defined as: &lt;/p&gt;&lt;blockquote&gt; generics is a technique that allows one value to take different datatypes (so-called polymorphism) as long as certain contracts such as subtypes and signature are kept. The programming style emphasizing use of this technique is called generic. &lt;/blockquote&gt;  &lt;p&gt; For example, a &lt;emp&gt;List&lt;/emp&gt; object can contains different elements &lt;emp&gt;String&lt;/emp&gt;, &lt;emp&gt;Integer&lt;/emp&gt;, etc. In generics, we can declare a List object only contains certain types in elements. E.g, List&lt;string&gt; as a List object only contains String objects.  &lt;/string&gt;&lt;/p&gt;&lt;p&gt; Generics is easily mixing up with the term &lt;emp&gt;template&lt;/emp&gt;. In Java, the syntax of generics is similar to Template in C++. However, generics and Template are two different concept. Template is about code generation, and generics is  about type checking. You can refer to a Wikipedia's article:  &lt;a href="http://en.wikipedia.org/wiki/Comparison_of_generics_to_templates"&gt; Comparison of generics to templates&lt;/a&gt;.  &lt;/p&gt;&lt;p&gt; With generics, it can avoid type-safe problem of collection framework of Java. However, the generics in Java is very complicated. It is not elegant. After you read the &lt;a href="http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf"&gt; tutorial of generics&lt;/a&gt;, you may feel very confusing, and you may find that there are many exceptional cases need to take care when using generics in Java.  &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1256658044816953442?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1256658044816953442' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1256658044816953442'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1256658044816953442'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/10/java-generics.html' title='Java Generics'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-8523551267976425776</id><published>2005-10-30T13:20:00.000+08:00</published><updated>2006-11-19T13:22:09.266+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Fix the RAID</title><content type='html'>Yesterday, I found that one of my harddisk in my Old PC has bad sectors.  I decided not to replace the bad harddisk but to relocate the root partition to other free spaces in the harddisk.    Originally, the RAID of root filesystem contains the hda8 and hdc8 partitions. The bad sectors were found in hda8. I try to search whether there exists unused partition on hda.  I find hda7 is not used and the size matches the hdc8. To add hda7 to the RAID:  &lt;pre&gt;raidhotadd /dev/md0 /dev/hda7&lt;br /&gt;&lt;/pre&gt;  From "/proc/mdstat", it shows hda7 is adding to md0. Wait for a while, mirroring of data from hdc8 to hda7 finished. I restart the PC.  &lt;p&gt; After startup, it fails. The OS still try to use hda8 as the RAID. After some inspection, it is due to the configuration problem. First, it needs to correct the "/etc/mdadm/mdadm.conf" file. Second, it needs to regenerate the initrd image using the "mkinitrd" command.  Lastly, it needs to correct the GURB config. Then, I restart te PC and this round, it works!    &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-8523551267976425776?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=8523551267976425776' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/8523551267976425776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/8523551267976425776'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/10/fix-raid.html' title='Fix the RAID'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-7712538253846614903</id><published>2005-10-29T12:16:00.000+08:00</published><updated>2006-11-19T13:18:32.303+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='www'/><title type='text'>GIF vs PNG</title><content type='html'>Today, I test my homepage with IE. IE cannot display transparent PNG graphics properly, and the background becomes grey in color.    &lt;p&gt; Fortunately, I find a workaround on the Web --  &lt;a href="http://homepage.ntlworld.com/bobosola/"&gt; http://homepage.ntlworld.com/bobosola/&lt;/a&gt;.   It has details about the problem and how to solve it. In short, it uses javascript to patch all &amp;lt;img&amp;gt; tag of PNG graphic's CSS using the "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" of IE.  &lt;/p&gt;&lt;p&gt; Actually, PNG has some advantages over GIF. &lt;/p&gt;&lt;ol&gt;&lt;li&gt; Max color depth of PNG is 24-bit but that of GIF is 8-bit. &lt;/li&gt;&lt;li&gt; PNG has higher compression rate than GIF. &lt;/li&gt;&lt;li&gt; PNG support alpha channel transparency but GIF only support binary transparency. &lt;/li&gt;&lt;/ol&gt; However, GIF supports animation but PNG not. This is a weak point of PNG.  &lt;p class="note"&gt; Related Links:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/workshop/author/filter/reference/filters/alphaimageloader.asp"&gt;AlphaImageLoader Filter&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.libpng.org/pub/png/"&gt;PNG Offical Site&lt;/a&gt;   &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-7712538253846614903?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=7712538253846614903' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/7712538253846614903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/7712538253846614903'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/10/gif-vs-png.html' title='GIF vs PNG'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-3027083832353018027</id><published>2005-10-25T11:43:00.000+08:00</published><updated>2006-11-19T12:44:50.024+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Makefile to Build Homepage</title><content type='html'>After study GNU Make yesterday, I write a generic Makefile for building my homepage today.   &lt;p&gt; The the following is the Generic Makefile: &lt;/p&gt;&lt;pre&gt;PHP=php&lt;br /&gt;&lt;br /&gt;all: premake all_subdirs all_curdirpages postmake&lt;br /&gt;&lt;br /&gt;premake:&lt;br /&gt; if test -x ./premake.sh; then ./premake.sh; fi&lt;br /&gt;&lt;br /&gt;postmake:&lt;br /&gt; if test -x ./postmake.sh; then ./postmake.sh; fi&lt;br /&gt;&lt;br /&gt;include Makefile.dep&lt;br /&gt;&lt;br /&gt;all_subdirs: $(subdirs)&lt;br /&gt; for dir in $(subdirs); do (cd $$dir; make); done&lt;br /&gt;&lt;br /&gt;all_curdirpages: $(pages)&lt;br /&gt;&lt;br /&gt;$(filter %.html,$(pages)): %.html: %.tpl&lt;br /&gt; $(PHP)  $&lt; &gt; $@&lt;br /&gt; touch timestamp&lt;br /&gt;&lt;br /&gt;clean:&lt;br /&gt; for dir in $(subdirs); do (cd $$dir; make clean); done&lt;br /&gt; rm -f *.html timestamp *.gen&lt;br /&gt;&lt;br /&gt;.PHONY: all clean all_subdirs all_curdirpages premake postmake $(subdirs) $(dep_phony)&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt;  This Makefile is put (symbolic-link) in all sub-directories of the homepage. In other words, all sub-directories use the same Makefile. So, it is called &lt;emp&gt;generic&lt;/emp&gt; Makefile. If it needs to add some extra logics before or after make, we can create "premake.sh" and "postmake.sh" shell scripts respectively. The scripts will be executed accordingly.  In the Makefile, the marco "pages", "subdirs" and "dep_phony" are provided by the "Makefile.dep" The customization depends on the "Makefile.dep".  In each directory, it should contain a "Makefile.dep". The following is a sample "Makefile.dep":  &lt;/p&gt;&lt;pre&gt;subdirs=blog secImage&lt;br /&gt;&lt;br /&gt;pages=index.html tba.html contact.html&lt;br /&gt;&lt;br /&gt;index.html: index.tpl header.tpl footer.tpl rightbar.tpl \&lt;br /&gt; lib/search.tpl lib/acknowledgement.tpl blog/recent/index.html&lt;br /&gt;&lt;br /&gt;contact.html: contact.tpl header.tpl footer.tpl rightbar.tpl \&lt;br /&gt; lib/search.tpl lib/acknowledgement.tpl&lt;br /&gt;&lt;br /&gt;tba.html: tba.tpl header.tpl footer.tpl&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; The "subdirs" macro defines the the sub-directories requiring to process, and the "pages" macro defines the HTML pages requiring to generated.  The "Makefile.dep" file also defines the dependency of HTML files to the template files (*.tpl). &lt;/p&gt;&lt;p&gt; To build the homepage, I only need to issue the "make" command in the root  directory of the homepage source.    &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-3027083832353018027?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=3027083832353018027' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3027083832353018027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/3027083832353018027'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/10/makefile-to-build-homepage.html' title='Makefile to Build Homepage'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1341756897662931353</id><published>2005-10-24T13:22:00.000+08:00</published><updated>2006-11-18T14:27:46.762+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='www'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Designing My Homepage</title><content type='html'>I want to host my homepage in my NLSU2-Linux box. Today, it's the time to think about it.  Since the NLSU2-Linux box is not a powerful machine, it is not appropriate to use Java technology. To put less load on the CPU, it should avoid using too much dynamic pages.   &lt;p&gt; In my past experience, using static HTML, there are many duplication parts among different pages, for example, the page header, page footer, menus.... This make the web-site difficult to maintain. If I need to changes the page header, I need to edit nearly all HTML pages repeatedly.  In programming, we avoid code duplication by using functions.  How about make web pages? I think &lt;emp&gt;template&lt;/emp&gt; is a solution.  &lt;/p&gt;&lt;p&gt; In my homepage, I decided to use PHP as the template language. (To avoid confusion with PHP scripts for dynamic pages, the extension of template files is ".tpl") The following shows a typical page contains header and footer in PHP:  &lt;/p&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;? include 'header.tpl' ?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new;"&gt;.... the contents here .....&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&lt;br /&gt;&amp;lt? include 'footer.tpl' ?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The "header.tpl" and "footer.tpl" are PHP scripts which generate the header and footer HTML fragments respectively.  In PHP, the "include" function embedded the contents of the specific file in current pages, similar to the "include" directive in C/C++.  In the homepage, every pages contains header and footer will be like the above example.  If we want to change the header, we only need to change the "header.tpl" file once.  &lt;p&gt;  However, we need to convert the PHP file to HTML. For example, we have an "index.tpl" file which is a PHP script for generating "index.html". We can issue the following commands: &lt;/p&gt;&lt;pre&gt;php index.tpl &gt; index.html&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; For a complete homepage, there should be many ".tpl" files. I think nobody want to type the above command line again and again. GNU Make is a good utility to do this  task.   &lt;/p&gt;&lt;p&gt;Since I only have some experience to create a simple "Makefile", it is not enough for handling a complete homepage. I spent some hours to study the GNU Make and hope  I can create a generic Makefile tomorrow.  &lt;/p&gt;&lt;p style="font-style: italic;" class="note"&gt;Related links:&lt;br /&gt;&lt;a href="http://www.php.net/"&gt;PHP&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.gnu.org/software/make/"&gt;GNU Make&lt;/a&gt;  &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1341756897662931353?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1341756897662931353' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1341756897662931353'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1341756897662931353'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/10/designing-my-homepage.html' title='Designing My Homepage'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-4395330144383303154</id><published>2005-10-21T12:42:00.000+08:00</published><updated>2006-11-18T14:14:24.193+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Purchased Linksys NSLU2</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger2/2038/3427/1600/382970/D20-1.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://photos1.blogger.com/x/blogger2/2038/3427/320/364070/D20-1.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I want to setup a 7x24 server at home. The main purpose of this server is for hosting my homepage and files sharing with my friends.  After some googling, I found the &lt;a href="http://www.linksys.com/servlet/Satellite?childpagename=US%2FLayout&amp;packedargs=c%3DL_Product_C2%26cid%3D1115416906769%26site%3DUS&amp;amp;pagename=Linksys%2FCommon%2FVisitorWrapper"&gt;Linksys NSLU2&lt;/a&gt; is quite suitable for this purposes.    &lt;p&gt; NSLU2 is just a SOHO-grade network attached device with simple functions. However, it can be turned into a more powerful Linux box with the help of &lt;a href="http://www.nslu2-linux.org/"&gt;NSLU2-Linux&lt;/a&gt; project. Then, I can have a lower power consumption, ultra-slim and fanless server :P &lt;/p&gt;&lt;p&gt; Finally, I bought it at Golden Shopping Center. The following is a photo of my running NSLU2 : )&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-4395330144383303154?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=4395330144383303154' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4395330144383303154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/4395330144383303154'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2005/10/purchased-linksys-nslu2.html' title='Purchased Linksys NSLU2'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28076022.post-1967633490979167112</id><published>2005-10-18T13:16:00.000+08:00</published><updated>2006-11-18T14:24:22.741+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Start Hacking the NSLU2</title><content type='html'>Today, I had annual leave. I had full day to hack my NSLU2 box. After read the wiki of &lt;a herf="http://www.nslu2-linux.org/wiki/Main/HomePage"&gt;NSLU2-Linux project&lt;/a&gt;, I decided to install the Unslung firmware. I followed the user guide and  reflashed the firmware of the NSLU2 box. Everything worked fine. :)  &lt;p&gt; Next, I setup the SSH, so I can remotely access the NSLU2 box. Then, PHP, Perl, and other useful utilities have been installed. I also setup a native compilation environment in the NSLU2 box, such that it can compile additional software packages.  &lt;/p&gt;&lt;p&gt; Moreover, I tried to setup a cross compilation environment in my old PC which running Debian.  This can help me to compile any additional packages faster. However, I fail to compile the cross compilation environment. Then, I read the guide in Wiki carefully, I found that I missed to install some necessary packages (flex, bison, rsync...). After installed the necessary packages, the cross compilation environment was compiled successfully.   &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/28076022-1967633490979167112?l=ahlamnote.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=28076022&amp;postID=1967633490979167112' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1967633490979167112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28076022/posts/default/1967633490979167112'/><link rel='alternate' type='text/html' href='http://ahlamnote.blogspot.com/2006/11/start-hacking-nslu2.html' title='Start Hacking the NSLU2'/><author><name>Ah Lam</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
