<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alex on Linux&#187; Short articles</title>
	<atom:link href="http://www.alexonlinux.com/category/articles/short-articles/feed" rel="self" type="application/rss+xml" />
	<link>http://www.alexonlinux.com</link>
	<description></description>
	<lastBuildDate>Sun, 25 Jul 2010 10:00:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Call a constructor or allocate an object in-place</title>
		<link>http://www.alexonlinux.com/call-a-constructor-or-allocate-an-object-in-place-2</link>
		<comments>http://www.alexonlinux.com/call-a-constructor-or-allocate-an-object-in-place-2#comments</comments>
		<pubDate>Sun, 04 Jul 2010 20:40:10 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[memory management]]></category>
		<category><![CDATA[new]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1803</guid>
		<description><![CDATA[Since I joined Dell, my main field of research and work has somewhat changed. Now I am mostly working with C++ and file-systems. This world is not entirely new to me, but apparently I have a lot of stuff to learn. Today I&#8217;d like to talk about one nice trick that I learned few days [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Permanent Link: Direct IO in Python'>Direct IO in Python</a></li>
<li><a href='http://www.alexonlinux.com/one-sane-voice-in-the-crowd' rel='bookmark' title='Permanent Link: One sane voice in the crowd'>One sane voice in the crowd</a></li>
<li><a href='http://www.alexonlinux.com/recursively-deleting-symbolic-link-and-what-it-points-to' rel='bookmark' title='Permanent Link: Recursively deleting symbolic link and what it points to'>Recursively deleting symbolic link and what it points to</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Since I joined Dell, my main field of research and work has somewhat changed. Now I am mostly working with C++ and file-systems. This world is not entirely new to me, but apparently I have a lot of stuff to learn.</p>
<p>Today I&#8217;d like to talk about one nice trick that I learned few days ago.</p>
<p>When working with large software systems, memory management becomes an imperative. In C, you can easily allocate a large chunk of memory and allocate structure right on that buffer. This is by far more difficult in C++, because compiler has to call consturctor.</p>
<p>Apparently, you can, in a way, directly call object&#8217;s constructor . I.e. you can allocate an object, on specified memory region, without actually allocating this region.</p>
<p>This is how you do it.</p>
<pre class="brush:cpp">char* s = new char[1024];

SomeClass* p = new (s) SomeClass;
</pre>
<p>First new operator just allocates 1024 bytes. This is good old allocation as we know it. Note the special syntax of the second new operator. It allocates the new object on memory specified in brackets. Basically, this calls SomeClass&#8217;s constructor using s as storage.</p>
<p><em>One thing that I don&#8217;t know how to do is how to call destructor on the object &#8211; i.e. how to delete an object in place.</em></p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Permanent Link: Direct IO in Python'>Direct IO in Python</a></li>
<li><a href='http://www.alexonlinux.com/one-sane-voice-in-the-crowd' rel='bookmark' title='Permanent Link: One sane voice in the crowd'>One sane voice in the crowd</a></li>
<li><a href='http://www.alexonlinux.com/recursively-deleting-symbolic-link-and-what-it-points-to' rel='bookmark' title='Permanent Link: Recursively deleting symbolic link and what it points to'>Recursively deleting symbolic link and what it points to</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/call-a-constructor-or-allocate-an-object-in-place-2/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How less processes its input</title>
		<link>http://www.alexonlinux.com/how-less-processes-its-input</link>
		<comments>http://www.alexonlinux.com/how-less-processes-its-input#comments</comments>
		<pubDate>Wed, 28 Apr 2010 13:37:37 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[curses]]></category>
		<category><![CDATA[error stream]]></category>
		<category><![CDATA[file descriptor]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[input stream]]></category>
		<category><![CDATA[less]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[more]]></category>
		<category><![CDATA[output stream]]></category>
		<category><![CDATA[tty]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1783</guid>
		<description><![CDATA[Here&#8217;s an interesting bit I ran into few days ago. I got curious how is that less (or more) can read file contents from standard input and yet it is able to process input that comes from user. Both of them come from standard input, yet these are quiet heterogeneous streams of information. So, how [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/creating-new-application-on-top-of-ssh' rel='bookmark' title='Permanent Link: Creating new application on top of SSH'>Creating new application on top of SSH</a></li>
<li><a href='http://www.alexonlinux.com/sed-the-missing-manual' rel='bookmark' title='Permanent Link: sed &#8211; the missing manual'>sed &#8211; the missing manual</a></li>
<li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Permanent Link: Direct IO in Python'>Direct IO in Python</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an interesting bit I ran into few days ago. I got curious how is that <em>less</em> (or <em>more</em>) can read file contents from standard input and yet it is able to process input that comes from user. Both of them come from standard input, yet these are quiet heterogeneous streams of information. So, how can it be?</p>
<p><span id="more-1783"></span>At first, I thought <em>less</em> reads entire input first. This would make standard input stream free to process key presses from the user. So I decided to check this out. I created a 1Gb long text file and ran <em>less</em> on it. I expected <em>less</em> to take some time to show file contents, but it showed first lines of the file instantly. Also, it didn&#8217;t consume 1Gb of RAM as I expected.</p>
<p>The conclusion is obvious. <em>less</em> does not read entire input buffer before letting user to interact with itself. Then how?</p>
<p>Here&#8217;s what <em>less</em> does. It separates input file stream from user input stream. Both inputs initially come via standard input stream, so <em>less</em> separates between them. First it duplicates the standard input stream. This allocates a new file descriptor. Then it closes old file descriptor, freeing file descriptor 0 for use. Then it opens /dev/tty. When opening a file, Linux uses next available file descriptor. File descriptor used as standard input is 0, so when <em>less</em> opens /dev/tty again, file descriptor of the newly opened file has value 0.</p>
<p>Eventually, it ends up with the new input coming via standard input stream file descriptor (0), and old input still available via file descriptor that it duplicated in the beginning. It reads the input file from the duplicated file descriptor, and uses curses on standard input stream.</p>
<p>You may be wondering what is /dev/tty and what it has to do with standard input streams. This is really fascinating stuff.</p>
<p>As you know, in Linux, everything is a file. So is terminal. Linux uses device files to represent various system devices. /dev/tty is a file that represents terminal of the current process. When process reads from /dev/tty it becomes its input. When program writes to /dev/tty it becomes its standard output or standard error stream.</p>
<p>So, when <em>less </em>reopens /dev/tty, it actually recreates standard input. Older descriptor, one that has been duplicated, can no longer accept new input, but <em>less</em> still can use it to read what it has been written into it already.</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/creating-new-application-on-top-of-ssh' rel='bookmark' title='Permanent Link: Creating new application on top of SSH'>Creating new application on top of SSH</a></li>
<li><a href='http://www.alexonlinux.com/sed-the-missing-manual' rel='bookmark' title='Permanent Link: sed &#8211; the missing manual'>sed &#8211; the missing manual</a></li>
<li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Permanent Link: Direct IO in Python'>Direct IO in Python</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/how-less-processes-its-input/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursively deleting symbolic link and what it points to</title>
		<link>http://www.alexonlinux.com/recursively-deleting-symbolic-link-and-what-it-points-to</link>
		<comments>http://www.alexonlinux.com/recursively-deleting-symbolic-link-and-what-it-points-to#comments</comments>
		<pubDate>Mon, 01 Feb 2010 08:52:59 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Code library]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1703</guid>
		<description><![CDATA[Recently I looked for a solution to this little problem. how do you, programmatically, delete a symbolic link and a file that it points to? One problem that you should take care of when tackling this problem, is that symbolic link can point to a symbolic link. Then symbolic link should also point to symbolic [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/hex-dump-functions' rel='bookmark' title='Permanent Link: Hex dump functions'>Hex dump functions</a></li>
<li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Permanent Link: Direct IO in Python'>Direct IO in Python</a></li>
<li><a href='http://www.alexonlinux.com/how-less-processes-its-input' rel='bookmark' title='Permanent Link: How less processes its input'>How less processes its input</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Recently I looked for a solution to this little problem. how do you, programmatically, delete a symbolic link and a file that it points to?</p>
<p>One problem that you should take care of when tackling this problem, is that symbolic link can point to a symbolic link. Then symbolic link should also point to symbolic link. And once again, and again and again&#8230;</p>
<p><span id="more-1703"></span>So what can we do about it? First, lets start with <em>lstat</em>() system all. It will tell us is the file we&#8217;re interested in, is actually a symbolic link. To be more precise, <em>st_mode</em> field in <em>struct stat</em> will have flag S_IFLNK if specified file is a symbolic link. Note that it should be <em>lstat</em>() and not <em>stat</em>() &#8211; the later will return information about file the link points to and not about the link.</p>
<p>Next step is to call <em>readlink</em>(). This system call returns name of the file pointed to by specified symbolic link.</p>
<p>Finally, you should repeat the process recursively, for the pointed to file. Here is the code that does it:</p>
<pre class="brush:cpp">int recursive_deleter(const char* filename)
{
  struct stat st;
  char buffer[1024];

  if (lstat(filename, &amp;st)) {
    perror("stat");
    return -1;
  }     

  if (st.st_mode &amp; S_IFLNK == S_IFLNK) {
    memset(buffer, 0, sizeof(buffer));
    if (readlink(filename, buffer, sizeof(buffer)) &lt; 0) {
      perror("readlink");
      return -1;
    }           

    printf("File %s is a symbolic link to %s\n", filename, buffer);

    if (recursive_deleter(buffer))
      return 0;
  }     

  printf("Deleting %s\n", filename);

  if (unlink(filename)) {
    perror("unlink");
    return -1;
  }     

  return 0;
}
</pre>
<p>Have fun!</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/hex-dump-functions' rel='bookmark' title='Permanent Link: Hex dump functions'>Hex dump functions</a></li>
<li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Permanent Link: Direct IO in Python'>Direct IO in Python</a></li>
<li><a href='http://www.alexonlinux.com/how-less-processes-its-input' rel='bookmark' title='Permanent Link: How less processes its input'>How less processes its input</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/recursively-deleting-symbolic-link-and-what-it-points-to/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Direct IO in Python</title>
		<link>http://www.alexonlinux.com/direct-io-in-python</link>
		<comments>http://www.alexonlinux.com/direct-io-in-python#comments</comments>
		<pubDate>Tue, 12 Jan 2010 07:50:06 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1684</guid>
		<description><![CDATA[Doing file I/O of any kind in Python is really easy. You can start with plain open() and friends, working with Python&#8217;s file objects. by the way, Python&#8217;s open() resembles C&#8216;s fopen() so closely that I can&#8217;t stop thinking that open() may be based on fopen(). When its not enough, you can always upgrade to [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/whats-is-direct-io-anyway' rel='bookmark' title='Permanent Link: What&#8217;s is direct I/O anyway?'>What&#8217;s is direct I/O anyway?</a></li>
<li><a href='http://www.alexonlinux.com/call-a-constructor-or-allocate-an-object-in-place-2' rel='bookmark' title='Permanent Link: Call a constructor or allocate an object in-place'>Call a constructor or allocate an object in-place</a></li>
<li><a href='http://www.alexonlinux.com/recursively-deleting-symbolic-link-and-what-it-points-to' rel='bookmark' title='Permanent Link: Recursively deleting symbolic link and what it points to'>Recursively deleting symbolic link and what it points to</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Doing file I/O of any kind in Python is really easy. You can start with plain <em>open()</em> and friends, working with Python&#8217;s file objects. by the way, Python&#8217;s <em>open()</em> resembles <em>C</em>&#8216;s <em>fopen()</em> so closely that I can&#8217;t stop thinking that <em>open()</em> may be based on <em>fopen()</em>.</p>
<p>When its not enough, you can always upgrade to <em>open()</em> and <em>close()</em> from <em>os</em> module. Opening man page on <em>open()</em> (the system call &#8211; open(2)) reveals all those O_something options that you can pass to <em>os.open()</em>. But not all of them can be used in Python. For example, if you open a file with <em>O_DIRECT</em> and then try to write to it, you will end up with some strange error message.</p>
<p><span id="more-1684"></span></p>
<pre class="brush:py">&gt;&gt;&gt; import os
&gt;&gt;&gt; f = os.open('file', os.O_CREAT | os.O_TRUNC | os.O_DIRECT | os.O_RDWR)
&gt;&gt;&gt; s = ' ' * 1024
&gt;&gt;&gt; os.write(f, s)
Traceback (most recent call last):
  File "", line 1, in
OSError: [Errno 22] Invalid argument
&gt;&gt;&gt;
</pre>
<p>Invalid argument?. What invalid argument? Hey there&#8217;s nothing wrong with those arguments&#8230;</p>
<p>Reading open(2) man page further reveals that working with <em>O_DIRECT</em> requires that all buffers used for I/O should be aligned to 512 byte boundary. But how can you have a memory buffer aligned to 512 bytes in Python?</p>
<p>Apparently, there&#8217;s a way. Python comes with a module called <em>mmap</em>. <em>mmap()</em> is a system call that allows one to map portion of file into memory. All writes to memory mapped file, go directly to file despite it looks like you&#8217;re working with plain memory buffer. Same with reads.</p>
<p>There&#8217;s one interesting thing about<em> mmap</em>. It works with granularity of one memory page &#8211; 4kb that is. So every memory mapped buffer is naturally memory aligned to 4kb, thus to 512 byte boundary too. But hey, shouldn&#8217;t <em>mmap</em> map files?</p>
<p>Well, apparently <em>mmap</em> can be used for memory allocations. I.e. specifying -1 as file descriptor does just that &#8211; allocates RAM, as much as you tell it. So, this is what we do:</p>
<pre class="brush:py">&gt;&gt;&gt; import os
&gt;&gt;&gt; import mmap
&gt;&gt;&gt;
&gt;&gt;&gt; f = os.open('file', os.O_CREAT | os.O_DIRECT | os.O_TRUNC | os.O_RDWR)
&gt;&gt;&gt; m = mmap.mmap(-1, 1024 * 1024)
&gt;&gt;&gt; s = ' ' * 1024 * 1024
&gt;&gt;&gt;
&gt;&gt;&gt; m.write(s)
&gt;&gt;&gt; os.write(f, m)
1048576
&gt;&gt;&gt; os.close(f)
&gt;&gt;&gt;</pre>
<p>Note that <em>mmap </em>memory buffer object behaves like a file. I.e. you can write into the buffer and read from it &#8211; like I do in line 8. More on it in <a href="http://docs.python.org/library/mmap.html" rel="nofollow"  onclick="return TrackClick('http%3A%2F%2Fdocs.python.org%2Flibrary%2Fmmap.html','official+documentation')">official documentation</a>.</p>
<p>Have fun! <img src='http://www.alexonlinux.com/wp-content/plugins/smilies-themer/modern/smile.gif' alt=':-)' class='wp-smiley' /> </p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/whats-is-direct-io-anyway' rel='bookmark' title='Permanent Link: What&#8217;s is direct I/O anyway?'>What&#8217;s is direct I/O anyway?</a></li>
<li><a href='http://www.alexonlinux.com/call-a-constructor-or-allocate-an-object-in-place-2' rel='bookmark' title='Permanent Link: Call a constructor or allocate an object in-place'>Call a constructor or allocate an object in-place</a></li>
<li><a href='http://www.alexonlinux.com/recursively-deleting-symbolic-link-and-what-it-points-to' rel='bookmark' title='Permanent Link: Recursively deleting symbolic link and what it points to'>Recursively deleting symbolic link and what it points to</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/direct-io-in-python/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Rethinking linked list insertion</title>
		<link>http://www.alexonlinux.com/rethinking-linked-list-insertion</link>
		<comments>http://www.alexonlinux.com/rethinking-linked-list-insertion#comments</comments>
		<pubDate>Sat, 19 Dec 2009 12:24:36 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code library]]></category>
		<category><![CDATA[Short articles]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1658</guid>
		<description><![CDATA[There is one nice thing in looking for a new job. That is, you meet lots of new people and have a chance to learn from them. For example in one of the companies I was asked about something called anti-debugging. I didn&#8217;t have a clue what that is and had to ask for an [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock' rel='bookmark' title='Permanent Link: pthread mutex vs pthread spinlock'>pthread mutex vs pthread spinlock</a></li>
<li><a href='http://www.alexonlinux.com/todo-list' rel='bookmark' title='Permanent Link: Todo list'>Todo list</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>There is one nice thing in looking for a new job. That is, you meet lots of new people and have a chance to learn from them. For example in one of the companies I was asked about something called anti-debugging. I didn&#8217;t have a clue what that is and had to ask for an explanation. Apparently, this is a set of techniques used to fool a debugger and make the code undebuggable.</p>
<p>Anyway, here&#8217;s something else that I learned during one of the interviews.</p>
<p><span id="more-1658"></span>I was asked to implement insertion into a linked list in <em>C</em>. Each list node has a number (<em>num</em>). Numbers in the list should be sorted in ascending order &#8211; node with lowest number should be first. Here is my naive implementation.</p>
<pre class="brush:cpp">void list_insert(int num)
{
        list_node_t *n, *tmp, *prev;

        n = allocate_node();
        n-&gt;num = num;

        if (!head) {
                head = n;
                n-&gt;next = NULL;
        } else {
                tmp = head;
                prev = NULL;
                while (tmp) {
                        if (tmp-&gt;num &gt;= n-&gt;num) {
                                if (prev == NULL) {
                                        head-&gt;next = n;
                                        n-&gt;next = NULL;
                                } else {
                                        n-&gt;next = tmp;
                                        prev-&gt;next = n;
                                }

                                break;
                        }

                        prev = tmp;
                        tmp = tmp-&gt;next;
                }

                if (!tmp) {
                        n-&gt;next = NULL;
                        prev-&gt;next = n;
                }
        }
}</pre>
<p>Yeah, well it is pretty long, but that&#8217;s how you do it, right? You have to make sure that the list is not empty (line 8 ) &#8211; if it is empty, then new node should be placed at the head of the list. Then we have to find right place for the new node and insert it into its position (lines 14-29). Finally, if we didn&#8217;t find a good position for the new node, we should put the node at the end of the list (lines 31-34).</p>
<p>When I showed this to the examiner he asked me to rethink the routine. In particular he didn&#8217;t like number of <em>if</em> statements. After an hour of discussing various optimizations, this is what we came up with.</p>
<pre class="brush:cpp">void list_insert(int num)
{
        list_node_t **tmp, *n;

        n = allocate_node();
        n-&gt;num = num;

        tmp = &amp;head;
        while (*tmp) {
                if ((*tmp)-&gt;num &gt;= n-&gt;num)
                        break;
                tmp = &amp;(*tmp)-&gt;next;
        }

/*
        (*tmp) = n;
       n-&gt;next = (*tmp)-&gt;next;
*/

/*
        The code in the comment above is broken. Thanks to jagan
        for pointing this out. Here's the right code.
*/
        n->next = *tmp;
        *tmp = n;
}</pre>
<p>There are several things that make this version better.</p>
<p>First of all, instead of having a pointer to current node (<em>tmp</em>) and previous node (<em>prev</em>), we have one pointer that corresponds to pointer to previous node. This way we can always get to the current node via <em>next</em> field in the previous node. Thus we don&#8217;t need two pointers anymore.</p>
<p>Also, this version uses pointer to pointer to node to traverse through the list. We don&#8217;t insert the node in the while loop anymore. Purpose of the while loop is to find right place for the new node. This spares <em>if</em> statement that tests if the list is empty and <em>if </em>statement in the loop.</p>
<p>Finally, once <em>tmp</em> points to the right place, we insert the node.</p>
<p>Second version runs faster too. I did a small program that tests both versions and it appears that the later version is something like 5% faster.</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock' rel='bookmark' title='Permanent Link: pthread mutex vs pthread spinlock'>pthread mutex vs pthread spinlock</a></li>
<li><a href='http://www.alexonlinux.com/todo-list' rel='bookmark' title='Permanent Link: Todo list'>Todo list</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/rethinking-linked-list-insertion/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>6 things that I miss in bash</title>
		<link>http://www.alexonlinux.com/6-things-that-i-miss-in-bash</link>
		<comments>http://www.alexonlinux.com/6-things-that-i-miss-in-bash#comments</comments>
		<pubDate>Tue, 09 Jun 2009 18:20:36 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[enhancement]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1395</guid>
		<description><![CDATA[What is the most frequently used piece of software on your computer? Here&#8217;s one program that holds one of the highest place in my list of most frequently used programs. I am talking about&#8230; bash. In case you don&#8217;t know, this is the program behind large portion of the Linux command line. It is the [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/one-sane-voice-in-the-crowd' rel='bookmark' title='Permanent Link: One sane voice in the crowd'>One sane voice in the crowd</a></li>
<li><a href='http://www.alexonlinux.com/creating-new-application-on-top-of-ssh' rel='bookmark' title='Permanent Link: Creating new application on top of SSH'>Creating new application on top of SSH</a></li>
<li><a href='http://www.alexonlinux.com/is-desktop-linux-too-fragmented-to-succeed' rel='bookmark' title='Permanent Link: Is desktop Linux too fragmented to succeed?'>Is desktop Linux too fragmented to succeed?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>What is the most frequently used piece of software on your computer? Here&#8217;s one program that holds one of the highest place in my list of most frequently used programs. I am talking about&#8230; <em>bash</em>.</p>
<p>In case you don&#8217;t know, this is the program behind large portion of the Linux command line. It is the program that actually makes majority of work turning Linux command line into such a magnificent tool it is.</p>
<p>As for use frequency, on my computer the only program that beats it is perhaps a web browser. I use it more often than mail client, text processor or just any other program.</p>
<p>Now, one thing that entertains me is that there is absolutely no hype around <em>bash</em>. I mean, you probably know that next version of Firefox coming tomorrow (I am writing this on June 9th, 2009). But do you know when next version of <em>bash</em> is coming? Do you even know what is the version of <em>bash</em> that you currently use? Well, you are not alone &#8211; I have no clue either <img src='http://www.alexonlinux.com/wp-content/plugins/smilies-themer/modern/smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><span id="more-1395"></span>One thing that concerns me is that <em>bash</em> almost didn&#8217;t change for the last ten years. I mean the only new feature that, to my knowledge, it didn&#8217;t support ten years ago is <em>bash_completion</em> &#8211; that is the advanced version of plain completion that it does to files. I could be wrong about this of course, but one thing is certain. Whatever the changes are, they are unnoticeable.</p>
<p>So, I thought that I&#8217;d compile a list of features that I would like to see in the upcoming version of <em>bash</em>. Now really, if only one of them would become a reality, I&#8217;d chew my pair of orange Crocs (I do have a pair of orange Crocs), put it on video and post it on youtube. Alright, I won&#8217;t do that. But it would still be very nice to see these happening.</p>
<p>The list:</p>
<h3>1 &#8211; History sharing</h3>
<p>I often open multiple shells. It would be really nice to be able to synchronize history between them. Right now, it seems that <em>bash</em> writes history file when it shuts down. If you open another session after history has been saved, you can access commands that you&#8217;ve typed in in the previous session. Otherwise, the history between two sessions is completely independent. Not good.</p>
<h3>2 &#8211; Completion of directory and file names based on their usage</h3>
<p>I think that 90% of <em>cd</em>&#8216;s that I do are all destined to the same directory. Why on earth I see  the list of possible destination for <em>cd</em> in alphabetical order every time I press TAB?</p>
<h3>3 &#8211; Completion of make targets</h3>
<p>I know this has already been implemented. But I am wondering why it isn&#8217;t part of <em>bash_completion</em> package on Ubuntu. OpenSuSE is no better &#8211; it does completion only to some <em>yast</em> stuff.</p>
<h3>4 &#8211; Show a browseable and searchable list of files when hitting TAB key twice</h3>
<p>I guess you all know that. Single TAB key completes a word if it can make a single match. Double TAB shows a list of choices for completion. In case the list is too long, it builds a long list and pipes it through <em>more</em>.</p>
<p>What I would like to see is a browseable and searchable list. One that I can browse with arrow keys. I also would like to be able to enter portion of the file name and in that case <em>bash</em> should filter out everything that doesn&#8217;t match the criteria I&#8217;ve entered.</p>
<h3>5 &#8211; Completion of <em>scp</em>, on remote host</h3>
<p>I guess it happened to all of us. Copying file to a remote computer with <em>scp</em>, is always difficult because you actually have to remember the path on remote computer. Wouldn&#8217;t it be great if <em>bash</em> could complete remote paths as well?</p>
<p>Now, I know this is very difficult to implement. Basically you have to spawn <em>ssh</em> with <em>ls</em> command, wait for it to complete and parse the results. Oh and there is a password thing. You gotta take care of password prompt that <em>ssh</em> may produce. Have no idea how to solve this issue. I do see a couple of options, but all of them are far from being ideal.</p>
<h3>6 &#8211; Fix typos</h3>
<p>This one is simple. As long as I don&#8217;t hit the TAB key, no need to fix anything. Once I hit the TAB key, shell should check if the command I&#8217;ve entered makes sense and if not try to fix it. Good example of what could make sense are file names. <em>vi &lt;filename&gt; </em>probably means that you want to edit a file. If the file does not exist and yet there&#8217;s another file with almost identical name, fix it. Same with <em>cd</em>. You don&#8217;t <em>cd</em> into directories that don&#8217;t exist. So once shell detects an attempt to do so and the user asks for help (by pressing the TAB key), shell can fix the typo and make the user smile.</p>
<p>This is it. I hope to see any of these happening one day. In the meantime, enjoy the list and by all means leave comments with your ideas of <em>bash</em> enhancements.</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/one-sane-voice-in-the-crowd' rel='bookmark' title='Permanent Link: One sane voice in the crowd'>One sane voice in the crowd</a></li>
<li><a href='http://www.alexonlinux.com/creating-new-application-on-top-of-ssh' rel='bookmark' title='Permanent Link: Creating new application on top of SSH'>Creating new application on top of SSH</a></li>
<li><a href='http://www.alexonlinux.com/is-desktop-linux-too-fragmented-to-succeed' rel='bookmark' title='Permanent Link: Is desktop Linux too fragmented to succeed?'>Is desktop Linux too fragmented to succeed?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/6-things-that-i-miss-in-bash/feed</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>pthread mutex vs pthread spinlock</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock</link>
		<comments>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock#comments</comments>
		<pubDate>Sun, 17 May 2009 12:16:41 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[mutex]]></category>
		<category><![CDATA[pthread]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[spinlock]]></category>
		<category><![CDATA[synchronization]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303</guid>
		<description><![CDATA[Update 06/16/2009: On several occasions, commentators to this article pointed out that this post is somewhat incomplete. Therefore, before I continue, I would like to make some things clear. Before considering the code below, please note that spinlocks are totally useless on uni-processor computers. This is due to a nature of spinlocks, which I will [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/pthread-spinlocks' rel='bookmark' title='Permanent Link: pthread spinlocks'>pthread spinlocks</a></li>
<li><a href='http://www.alexonlinux.com/do-you-need-mutex-to-protect-int' rel='bookmark' title='Permanent Link: Do you need a mutex to protect an <em>int</em>?'>Do you need a mutex to protect an <em>int</em>?</a></li>
<li><a href='http://www.alexonlinux.com/multithreaded-simple-data-type-access-and-atomic-variables' rel='bookmark' title='Permanent Link: Multithreaded simple data type access and atomic variables'>Multithreaded simple data type access and atomic variables</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><em>Update 06/16/2009: On several occasions, commentators to this article pointed out that this post is somewhat incomplete. Therefore, before I continue, I would like to make some things clear.</em></p>
<p><em>Before considering the code below, please note that spinlocks are totally useless on uni-processor computers. This is due to a nature of spinlocks, which I will describe in future posts.</em></p>
<p><em>Also, it is not the intent of this article to show that spinlocks better than mutexes in all circumstances. Spinlocks perform better than mutexes in this particular setup, on multi-processor computer. It does not mean that spinlocks are good for you. Apply your own judgment when considering using materials presented in this article for your needs.<br />
</em></p>
<p>In this article I would like to demonstrate you how spinlocks are more efficient than mutexes. I&#8217;ll demonstrate a program that does the following.</p>
<p><span id="more-1303"></span></p>
<p>It builds a list of integers and then starts two threads, each removing entries from the list. Since both threads work with the same list at the same time, list has to be protected with synchronization mechanism of some kind.</p>
<p>Depending on whether the program has been compiled with USE_SPINLOCK or not, it will use a spinlock or a mutex to protect the list. In any case, it will display number of seconds that has passed from the moment threads has been started, until they finish.</p>
<pre class="brush:cpp">#include &lt;stdio.h&gt;
#include &lt;pthread.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/syscall.h&gt;
#include &lt;errno.h&gt;
#include &lt;sys/time.h&gt;

#include &lt;list&gt;

#define LOOPS 10000000

using namespace std;

list&lt;int&gt; the_list;

#ifdef USE_SPINLOCK
pthread_spinlock_t spinlock;
#else
pthread_mutex_t mutex;
#endif

pid_t gettid() { return syscall( __NR_gettid ); }

void *consumer(void *ptr)
{
    int i;

    printf("Consumer TID %lu\n", (unsigned long)gettid());

    while (1)
    {
#ifdef USE_SPINLOCK
        pthread_spin_lock(&amp;spinlock);
#else
        pthread_mutex_lock(&amp;mutex);
#endif

        if (the_list.empty())
        {
#ifdef USE_SPINLOCK
            pthread_spin_unlock(&amp;spinlock);
#else
            pthread_mutex_unlock(&amp;mutex);
#endif
            break;
        }

        i = the_list.front();
        the_list.pop_front();

#ifdef USE_SPINLOCK
        pthread_spin_unlock(&amp;spinlock);
#else
        pthread_mutex_unlock(&amp;mutex);
#endif
    }

    return NULL;
}

int main()
{
    int i;
    pthread_t thr1, thr2;
    struct timeval tv1, tv2;

#ifdef USE_SPINLOCK
    pthread_spin_init(&amp;spinlock, 0);
#else
    pthread_mutex_init(&amp;mutex, NULL);
#endif

    // Creating the list content...
    for (i = 0; i &lt; LOOPS; i++)
        the_list.push_back(i);

    // Measuring time before starting the threads...
    gettimeofday(&amp;tv1, NULL);

    pthread_create(&amp;thr1, NULL, consumer, NULL);
    pthread_create(&amp;thr2, NULL, consumer, NULL);

    pthread_join(thr1, NULL);
    pthread_join(thr2, NULL);

    // Measuring time after threads finished...
    gettimeofday(&amp;tv2, NULL);

    if (tv1.tv_usec &gt; tv2.tv_usec)
    {
        tv2.tv_sec--;
        tv2.tv_usec += 1000000;
    }

    printf("Result - %ld.%ld\n", tv2.tv_sec - tv1.tv_sec,
        tv2.tv_usec - tv1.tv_usec);

#ifdef USE_SPINLOCK
    pthread_spin_destroy(&amp;spinlock);
#else
    pthread_mutex_destroy(&amp;mutex);
#endif

    return 0;
}</pre>
<p>Lets see how this little program works in greater detail. <em>main() </em>starts with initialization of a mutex or a spinlock, in lines 67-71. Next it initializes the list. Number of entries it will push into the list depends on LOOPS definition from line 10. Finally, in lines 77-81 it measures current time and spawns two threads. Then it waits for both threads to finish their job.</p>
<p>The thread, between lines 24 and 56, runs in a loop and pops entries from the list. Once the list is empty, thread exits. Each iteration of the loop it locks the mutex/spinlock and then unlocks it (lines 32-36 and 51-55).</p>
<p>Once both threads are over, <em>main()</em> will measure the time again and print difference between two measurements. This difference is how we measure effectiveness. The less time it took to run, the better.</p>
<p>Lets run the code and see how it performs, first with mutex and then with spinlock.</p>
<pre>~/lab/mutex-vs-spinlock --&gt; g++ -Wall -pthread main.cc
~/lab/mutex-vs-spinlock --&gt; ./a.out
Consumer TID 19602
Consumer TID 19603
Result - 7.99794
~/lab/mutex-vs-spinlock --&gt; g++ -DUSE_SPINLOCK -Wall -pthread main.cc
~/lab/mutex-vs-spinlock --&gt; ./a.out
Consumer TID 19610
Consumer TID 19611
Result - 2.587424
~/lab/mutex-vs-spinlock --&gt;</pre>
<p>As we can see, the picture is clear. We can see that using spinlock, it took 2.5 seconds to complete the test. However when used mutex, it took almost 8 seconds to complete. This is 3 times more time.</p>
<p>This proves that the spinlock is more effective in term of CPU consumption and speed.</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/pthread-spinlocks' rel='bookmark' title='Permanent Link: pthread spinlocks'>pthread spinlocks</a></li>
<li><a href='http://www.alexonlinux.com/do-you-need-mutex-to-protect-int' rel='bookmark' title='Permanent Link: Do you need a mutex to protect an <em>int</em>?'>Do you need a mutex to protect an <em>int</em>?</a></li>
<li><a href='http://www.alexonlinux.com/multithreaded-simple-data-type-access-and-atomic-variables' rel='bookmark' title='Permanent Link: Multithreaded simple data type access and atomic variables'>Multithreaded simple data type access and atomic variables</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Is desktop Linux too fragmented to succeed?</title>
		<link>http://www.alexonlinux.com/is-desktop-linux-too-fragmented-to-succeed</link>
		<comments>http://www.alexonlinux.com/is-desktop-linux-too-fragmented-to-succeed#comments</comments>
		<pubDate>Tue, 12 May 2009 08:07:39 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[marketing]]></category>
		<category><![CDATA[money]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1282</guid>
		<description><![CDATA[This question is especially relevant after yesterday&#8217;s fiasco. I ran into an article whose name is exactly Is desktop Linux too fragmented to succeed? The article argues that the fragmentation is what keeping Linux Desktop from beating Mac OS and even Windows. It is because the effort to create Linux desktop is scattered across multiple [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/ubuntu-904-with-wubi-failure' rel='bookmark' title='Permanent Link: Ubuntu 9.04 with Wubi &#8211; Failure'>Ubuntu 9.04 with Wubi &#8211; Failure</a></li>
<li><a href='http://www.alexonlinux.com/what-kept-me-from-sticking-to-ubuntu-as-a-desktop-solution' rel='bookmark' title='Permanent Link: What kept me from sticking to Ubuntu as a desktop solution'>What kept me from sticking to Ubuntu as a desktop solution</a></li>
<li><a href='http://www.alexonlinux.com/6-things-that-i-miss-in-bash' rel='bookmark' title='Permanent Link: 6 things that I miss in bash'>6 things that I miss in bash</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This question is especially relevant after <a href="http://www.alexonlinux.com/ubuntu-904-with-wubi-failure" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fubuntu-904-with-wubi-failure','yesterday%22s+fiasco')">yesterday&#8217;s fiasco</a>. I ran into an article whose name is exactly <a href="http://www.computerworld.com/action/article.do?command=viewArticleBasic&amp;taxonomyName=Software&amp;articleId=9132157&amp;taxonomyId=18&amp;pageNumber=2" rel="nofollow"  onclick="return TrackClick('http%3A%2F%2Fwww.computerworld.com%2Faction%2Farticle.do%3Fcommand%3DviewArticleBasic%26amp%3BtaxonomyName%3DSoftware%26amp%3BarticleId%3D9132157%26amp%3BtaxonomyId%3D18%26amp%3BpageNumber%3D2','Is+desktop+Linux+too+fragmented+to+succeed')">Is desktop Linux too fragmented to succeed</a>?</p>
<p>The article argues that the fragmentation is what keeping Linux Desktop from beating Mac OS and even Windows. It is because the effort to create Linux desktop is scattered across multiple distribution, it cannot become a serious player in desktop solutions.</p>
<p>Toward its end, the article gives optimistic prospects. There are some efforts to bring Linux desktop community to common ground, unanswered though.</p>
<p><span id="more-1282"></span></p>
<h2>This is so wrong</h2>
<p>The truth is that are some points in the article that made my eyebrows go up. You see, having single desktop Linux distribution is impossible. This is against the nature of Linux and how its being distributed.</p>
<p>To get it moving you have to talk big distributors into this. But for big distributors, their desktop solution is one way or another their selling point. RedHat compete with Novell through Fedora and OpenSuSE. Moreover, they don&#8217;t want common ground. They want to compete.</p>
<p>Small distributions want their piece of the big cake too. Asking them to provide the same desktop solution would be as asking them to close their business &#8211; if they wanted to be a part of joined effort to make the world better place and Linux better desktop OS, people behind the distro could simply join someone else&#8217;s project.</p>
<p>Actually, this entire idea seems to be taken from socialism. We take something from everyone and create something that everyone would use. Sounds great, but this creates so called moral hazards. This strips away the will of competition. And competition is the driving force behind many of the technological marvels that we see today in general and in Linux in particular.</p>
<h2>The only way to improve Linux&#8217;s position in desktop market is</h2>
<p>to invest money into development of better Linux desktop.</p>
<p>Actually the author of the article was addressing the same issue, but from different angle. Linux desktop needs money. It needs more graphical designers, more QA engineers and more software engineers.</p>
<p>It straggles to become a serious desktop operating system because no one did usability testing. Because no one hired best UI designers, as Apple did. Because no one had hired enough QA engineers to make sure that all the software indeed works.</p>
<p>One way to overcome this problem is indeed by combining the effort. The problem is that Fedora isn&#8217;t there to beat Windows in desktop OS market. Fedora is a beta version of RedHat&#8217;s server systems. Same can be said about OpenSuSE, Ubuntu and most of the Linux distros.</p>
<p>Obviously money can be spent on nothing useful. Hundred engineers will not do in one month what ten engineers do in ten month. However, financing creates opportunity. And opportunity is exactly what Linux desktop needs.</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/ubuntu-904-with-wubi-failure' rel='bookmark' title='Permanent Link: Ubuntu 9.04 with Wubi &#8211; Failure'>Ubuntu 9.04 with Wubi &#8211; Failure</a></li>
<li><a href='http://www.alexonlinux.com/what-kept-me-from-sticking-to-ubuntu-as-a-desktop-solution' rel='bookmark' title='Permanent Link: What kept me from sticking to Ubuntu as a desktop solution'>What kept me from sticking to Ubuntu as a desktop solution</a></li>
<li><a href='http://www.alexonlinux.com/6-things-that-i-miss-in-bash' rel='bookmark' title='Permanent Link: 6 things that I miss in bash'>6 things that I miss in bash</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/is-desktop-linux-too-fragmented-to-succeed/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu 9.04 with Wubi &#8211; Failure</title>
		<link>http://www.alexonlinux.com/ubuntu-904-with-wubi-failure</link>
		<comments>http://www.alexonlinux.com/ubuntu-904-with-wubi-failure#comments</comments>
		<pubDate>Sun, 10 May 2009 20:03:20 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[disk]]></category>
		<category><![CDATA[failure]]></category>
		<category><![CDATA[israel]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[wireless]]></category>
		<category><![CDATA[wubi]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1268</guid>
		<description><![CDATA[Once every year or so, I get so frustrated with Windows Desktop that I decide to install Linux. I am a big fun of Ubuntu Linux. I use it for many things, this includes a server platform for this web-site. So most natural choice for me was to try Ubuntu 9.04, the latest version. I [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/is-desktop-linux-too-fragmented-to-succeed' rel='bookmark' title='Permanent Link: Is desktop Linux too fragmented to succeed?'>Is desktop Linux too fragmented to succeed?</a></li>
<li><a href='http://www.alexonlinux.com/what-kept-me-from-sticking-to-ubuntu-as-a-desktop-solution' rel='bookmark' title='Permanent Link: What kept me from sticking to Ubuntu as a desktop solution'>What kept me from sticking to Ubuntu as a desktop solution</a></li>
<li><a href='http://www.alexonlinux.com/few-thoughts-about-ubuntu-servers-and-centos' rel='bookmark' title='Permanent Link: Few thoughts about Ubuntu servers and CentOS'>Few thoughts about Ubuntu servers and CentOS</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Once every year or so, I get so frustrated with Windows Desktop that I decide to install Linux. I am a big fun of Ubuntu Linux. I use it for many things, this includes a server platform for this web-site. So most natural choice for me was to try Ubuntu 9.04, the latest version. I installed it on my Laptop computer using a program called <a href="http://wubi-installer.org/" rel="nofollow"  onclick="return TrackClick('http%3A%2F%2Fwubi-installer.org%2F','Wubi')">Wubi</a>.</p>
<p>Wubi is a program that installs Ubuntu Linux on top of installed Windows. I already had a Windows installation on my laptop, that I didn&#8217;t want to destroy. This is why I&#8217;ve chosen Wubi. It places root file-system in a file on Windows partition. Because of this feature, you don&#8217;t even need a partition to install Ubuntu.</p>
<p><span id="more-1268"></span></p>
<h2>What got me into this</h2>
<p>What got me into Linux desktop frenzy this time, is Vista&#8217;s slowness. We all know various virtues of Microsoft&#8217;s operating systems. But installing Linux desktop instead&#8230; Silly me. It took me just four hours to figure out that I am better with slowness. Four hours I usually don&#8217;t have.</p>
<p>I am full of respect to developers of Linux. I work with Linux and develop for it for many years and I think this is a great server platform, unmatched by any other OS. But, Linux desktop is unfortunately isn&#8217;t too mature to be a serious match for Windows as a Desktop OS.</p>
<p>Knowing this from my previous attempts to install Linux desktop, I tried a less destructive option out of all. That is, Wubi doesn&#8217;t change your existing Windows installation. It install Ubuntu Linux as if it was another Windows program.</p>
<h2>Installing Wubi</h2>
<p>Problems started with Wubi itself. I live in Israel and although I use English version of Vista, Wubi installation has decided that I am better with Hebrew. Entire installation procedure was in Hebrew.</p>
<p>Next, despite I explicitly told Wubi that I want English version of Ubuntu, it installed Hebrew version. I checked on Wubi&#8217;s web-site and it appeared someone reported this particular bug just few days before. And it already had a solution &#8211; developers presented a new revision of Wubi which wasn&#8217;t yet publicly available, but solved the problem. The installation interface language remained Hebrew, but at least it installed English version of Ubuntu.</p>
<p>Now in case you wonder why I had to reinstall entire operating system just because of interface language, I&#8217;ll explain you. You see, I am not very familiar with Ubuntu&#8217;s graphical interface and I didn&#8217;t know how to configure wireless network. Hebrew interface made it even more complicated for me, so I decided to get things right form the start and not to begin tackling problems on unfamiliar ground.</p>
<p>On the other hand, because I didn&#8217;t have internet access, I could not just install English support it as I would do otherwise.</p>
<h2>Now to Ubuntu</h2>
<p>My next task, after installing the Linux itself, was to configure wireless network. The installation program did detect both wired and wireless card. However, the network interfaces configuration program didn&#8217;t show the wireless interface &#8211; only the wired. Luckily, simply pressing Add solved the problem. New dialog, popped up, asking me what is my SSID.</p>
<p>I am lucky to have some background in wireless networking, otherwise I would not know what SSID is. In case you&#8217;re wondering, this is the name of your wireless network. Anyway, it appeared that I&#8217;ve forgotten name of my wireless network and I had to use my cell. phone (which luckily supports wi-fi) to find the name. Not to mention I&#8217;ve absolutely forgotten that I&#8217;ve used WPA2-PSK security for my network. I had to choose it manually too, but before that I had to investigate it with my cell. phone.</p>
<p>I must say that Ubuntu could ship a program that scans for wireless networks, but it just wasn&#8217;t there.</p>
<p>On the bright side, once I entered right values for SSID and encryption, it got connected immediately.</p>
<h2>The breaking point</h2>
<p>The next thing I planned to do was mounting my Windows partitions. Somehow mounting my C: drive wasn&#8217;t that difficult. The desktop was empty. I right clicked on it, created a new directory and then double clicked on it. It opened gnome file explorer. Then I pressed the computer button and here they were, my CD-ROM and C: drive. Clicking on C: drive, created a C: drive icon on the desktop and I could safely delete the directory I created, knowing that I can always open gnome explorer by clicking on C: drive icon.</p>
<p>Now I know that there are several ways of opening gnome explorer, but I just couldn&#8217;t find them.</p>
<p>Anyway, note that I have two partitions and gnome explorer only showed me one of them. It appeared to me that something is wrong with D: drive and I should try to mount it. I went to Add/Remove programs and added a program called <em>Disk Management</em>. It seemed logical to me that I need some program that manipulates disks, so I searched for <em>disk </em>and found that <em>Disk Management</em> program. However, once I started it, it reported that I don&#8217;t have disks at all.</p>
<p>This was the breaking point. Playing around with Ubuntu was fun, but I had to stop and go back to the world of productivity &#8211; where at least sometimes things work.</p>
<h2>Conclusion</h2>
<p>Linux is a great operating system and like I mentioned I feel lots of respect to developers of Ubuntu and Linux for the job they are doing. This is especially true because I owe my income to Linux, for the last decade. Linux has given me a profession and I am grateful for that. However it seems that, regrettably, Ubuntu, one of the the undoubtful leaders among Linux distributions, is still too immature as a Desktop solution. Too many things are not obvious. Too many things just don&#8217;t work out of the box. Yes I could find a solution for everything, but I am just too busy person to search solutions for everything.</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/is-desktop-linux-too-fragmented-to-succeed' rel='bookmark' title='Permanent Link: Is desktop Linux too fragmented to succeed?'>Is desktop Linux too fragmented to succeed?</a></li>
<li><a href='http://www.alexonlinux.com/what-kept-me-from-sticking-to-ubuntu-as-a-desktop-solution' rel='bookmark' title='Permanent Link: What kept me from sticking to Ubuntu as a desktop solution'>What kept me from sticking to Ubuntu as a desktop solution</a></li>
<li><a href='http://www.alexonlinux.com/few-thoughts-about-ubuntu-servers-and-centos' rel='bookmark' title='Permanent Link: Few thoughts about Ubuntu servers and CentOS'>Few thoughts about Ubuntu servers and CentOS</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/ubuntu-904-with-wubi-failure/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>How to send SMS message with Python</title>
		<link>http://www.alexonlinux.com/how-to-send-sms-message-with-python</link>
		<comments>http://www.alexonlinux.com/how-to-send-sms-message-with-python#comments</comments>
		<pubDate>Thu, 02 Apr 2009 11:51:08 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[web interface]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1067</guid>
		<description><![CDATA[I can&#8217;t beleive all the things that you can do with Python. Obviously, whatever you can do with Python, you can do with a whole bunch of programming languages out there. What I am really impressed with, is the ease. Few weeks ago I was looking for a way to programatically send myself SMS on [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Permanent Link: Direct IO in Python'>Direct IO in Python</a></li>
<li><a href='http://www.alexonlinux.com/pythons-optparse-for-human-beings' rel='bookmark' title='Permanent Link: Python&#8217;s optparse for human beings'>Python&#8217;s optparse for human beings</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I can&#8217;t beleive all the things that you can do with Python. Obviously, whatever you can do with Python, you can do with a whole bunch of programming languages out there. What I am really impressed with, is the ease.</p>
<p>Few weeks ago I was looking for a way to programatically send myself SMS on certain occasions. I was (and still) developing a system that would check for certain conditions on a server and alert me when something is wrong.</p>
<p>Eventually, I came up with a Python script, <span style="text-decoration: underline;"><strong>40 lines</strong></span> long <img src='http://www.alexonlinux.com/wp-content/plugins/smilies-themer/modern/smile.gif' alt=':-)' class='wp-smiley' /> Note that you have to pay for the messages, but thats just few pennies. I bet there&#8217;s a way to plug into ICQ&#8217;s protocol and send SMS for free, but I don&#8217;t think you can do this with only 40 lines of code.<span id="more-1067"></span></p>
<p>Here is the idea. There are firms on the internet, that provide service called SMS gateway. These firms has special devices plugged into GSM network on one end and has some programmable interface on the other end.</p>
<p>Here&#8217;s what you do. You open an account with such a firm. Then you either pay for one message or buy some credits and then spend them by sending messages.</p>
<p>SMS gateway I used called <a href="http://www.world-text.com" rel="nofollow"  onclick="return TrackClick('http%3A%2F%2Fwww.world-text.com','world-text')">world-text</a>. Please, by all means I have nothing to do with these guys. I found them on the internet, just as you would.</p>
<p>There are couple of nice things about this particular company, although I bet if you spend some time researching you will find a better and probably cheaper one.</p>
<p>I don&#8217;t think there&#8217;s a standard for SMS gateways. Each company does something of its own. World-text provide web based gateway and this is what makes it so easy to use with Python.</p>
<p>Python code that I&#8217;ve written, simply sends properly formatted HTTP request to their web interface. Here&#8217;s the code.</p>
<pre class="brush:py">#!/usr/bin/python

import sys
import time
import glob
import httplib
import urllib

recepients = []

recepients.append("-------------")

world_text_username = "your@email.com"
world_text_password = "your password"

def usage():
    print "alertme.py &lt;message to send&gt;"
    sys.exit(0)

def send_sms(msg):
    global recepients, world_text_username, world_text_password

    print "Asked to send sms: %s" % msg

    for r in recepients:
        params = ""
        params = params + "username=" + world_text_username
        params = params + "&amp;password=" + world_text_password
        params = params + "&amp;" + urllib.urlencode({'message': msg})
        params = params + "&amp;sourceaddr=SMSAlert"
        params = params + "&amp;mobile=" + r
        headers = {"Content-Type": "application/x-www-form-urlencoded"}
        conn = httplib.HTTPConnection("sms.world-text.com:1081")
        conn.request("POST", "/sendsms", params, headers)
        conn.close();

if len(sys.argv) != 2:
    usage()

send_sms(sys.argv[1])</pre>
<p>To use the script, just append your phone number, including country and regional code to the recepients list &#8211; make sure to delete the &#8220;&#8212;&#8212;&#8212;-&#8221; from it. Next change <em>world_text_username </em>and <em>world_text_password</em> to something meaningful and you are ready to bombard yourself with SMS messages <img src='http://www.alexonlinux.com/wp-content/plugins/smilies-themer/modern/smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>In case you have further questions, email me at <a href="mailto:alex@alexonlinux.com" rel="nofollow" >alex@alexonlinux.com</a>.</p>
<p>Have fun! <img src='http://www.alexonlinux.com/wp-content/plugins/smilies-themer/modern/biggrin.gif' alt=':D' class='wp-smiley' /> </p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Permanent Link: Direct IO in Python'>Direct IO in Python</a></li>
<li><a href='http://www.alexonlinux.com/pythons-optparse-for-human-beings' rel='bookmark' title='Permanent Link: Python&#8217;s optparse for human beings'>Python&#8217;s optparse for human beings</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/how-to-send-sms-message-with-python/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
