<?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; Howto</title>
	<atom:link href="http://www.alexonlinux.com/category/articles/howto/feed" rel="self" type="application/rss+xml" />
	<link>http://www.alexonlinux.com</link>
	<description></description>
	<lastBuildDate>Sun, 05 Feb 2012 20:42:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>UML cheatsheet</title>
		<link>http://www.alexonlinux.com/uml-cheatsheet</link>
		<comments>http://www.alexonlinux.com/uml-cheatsheet#comments</comments>
		<pubDate>Mon, 19 Sep 2011 16:48:44 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code library]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[class diagram]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[UML]]></category>
		<category><![CDATA[uml diagram]]></category>
		<category><![CDATA[uml reference]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1945</guid>
		<description><![CDATA[Every once in awhile, I have to draw a UML diagram. I rarely do serious designs with UML, however sometimes I do need to depict some piece of code in a diagram and UML seems to be the best notation around. Unfortunately, various sources of information on UML tend to over-complicate things. I am not software architect [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Every once in awhile, I have to draw a UML diagram. I rarely do serious designs with UML, however sometimes I do need to depict some piece of code in a diagram and UML seems to be the best notation around.</p>
<p>Unfortunately, various sources of information on UML tend to over-complicate things. I am not software architect and drawing UMLs is not my job. So my UML skills are poor by definition. Moreover, I am happy with this situation and don&#8217;t see it changing in the future (even if I get promoted <img src='http://www.alexonlinux.com/wp-content/plugins/smilies-themer/modern/wink.gif' alt=';-)' class='wp-smiley' /> ).</p>
<p>So from time to time I need a simple UML reference card. Simple search finds references <a href="http://www.holub.com/goodies/uml/" rel="nofollow"  onclick="return TrackClick('http%3A%2F%2Fwww.holub.com%2Fgoodies%2Fuml%2F','like+this+one')">like this one</a>, which are excellent if you are serious about UML, and I am not.</p>
<p>Eventually, I decided to write a short UML class diagram reference card for myself. I hope you will enjoy it as well.<br />
<span id="more-1945"></span></p>
<h2>Inheritance</h2>
<p><a href="http://www.alexonlinux.com/wp-content/uploads/2011/09/child_inherits_from_parent.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fchild_inherits_from_parent.png','child_inherits_from_parent')"><img class="size-full wp-image-1952 aligncenter" title="child_inherits_from_parent" src="http://www.alexonlinux.com/wp-content/uploads/2011/09/child_inherits_from_parent.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fchild_inherits_from_parent.png','child_inherits_from_parent')" alt="" width="456" height="103" /></a></p>
<p>So, this is how classes inherit one from another. Here <em>Child class</em> inherits from <em>Parent Class</em>.</p>
<h2>Use</h2>
<p><a href="http://www.alexonlinux.com/wp-content/uploads/2011/09/user_uses_resource.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fuser_uses_resource.png','user_uses_resource')"><img class="size-full wp-image-1953 aligncenter" title="user_uses_resource" src="http://www.alexonlinux.com/wp-content/uploads/2011/09/user_uses_resource.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fuser_uses_resource.png','user_uses_resource')" alt="" width="445" height="104" /></a></p>
<p>This is how <em>User class</em> uses <em>Resource class</em>.</p>
<h2>Contains and manages</h2>
<p><a href="http://www.alexonlinux.com/wp-content/uploads/2011/09/whole_part_managed.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fwhole_part_managed.png','whole_part_managed')"><img class="size-full wp-image-1957 aligncenter" title="whole_part_managed" src="http://www.alexonlinux.com/wp-content/uploads/2011/09/whole_part_managed.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fwhole_part_managed.png','whole_part_managed')" alt="" width="429" height="107" /></a></p>
<p>Here, <em>Whole</em> class contains and manages <em>Part </em>class. This type of relation can be extended to one of the following:</p>
<ul>
<li>One to One</li>
<li>One to Many</li>
<li>Many to One</li>
<li>Many to Many</li>
</ul>
<h2>References</h2>
<p><a href="http://www.alexonlinux.com/wp-content/uploads/2011/09/whole_part_unmanaged.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fwhole_part_unmanaged.png','whole_part_unmanaged')"><img class="size-full wp-image-1959 aligncenter" title="whole_part_unmanaged" src="http://www.alexonlinux.com/wp-content/uploads/2011/09/whole_part_unmanaged.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fwhole_part_unmanaged.png','whole_part_unmanaged')" alt="" width="382" height="103" /></a></p>
<p>Here, <em>Whole</em> class references to <em>Part</em> class, but does not manage it. Again, can be extended with:</p>
<ul>
<li>One to One</li>
<li>One to Many</li>
<li>Many to One</li>
<li>Many to Many</li>
</ul>
<p>&nbsp;</p>
<p>This is enough information for now. I&#8217;ll probably extend it over time. In any case, please post your corrections and suggestions.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/uml-cheatsheet/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<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='Direct IO in Python'>Direct IO in Python</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='Direct IO in Python'>Direct IO in Python</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>7</slash:comments>
		</item>
		<item>
		<title>How to handle SIGSEGV, but also generate a core dump</title>
		<link>http://www.alexonlinux.com/how-to-handle-sigsegv-but-also-generate-core-dump</link>
		<comments>http://www.alexonlinux.com/how-to-handle-sigsegv-but-also-generate-core-dump#comments</comments>
		<pubDate>Sat, 07 Feb 2009 22:03:43 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Short articles]]></category>

		<guid isPermaLink="false">http://www.alexandersandler.net/?p=807</guid>
		<description><![CDATA[Recently I ran into this problem. How do you capture SIGSEGV with a signal handler and still generate a core file? The problem is that once you have your own signal handler for SIGSEGV, Linux will not call default signal handler which generates the core file. So, once you got SIGSEGV, consider all that useful [...]
Related posts:<ol>
<li><a href='http://www.alexonlinux.com/signal-handling-in-linux' rel='bookmark' title='Signal handling in Linux'>Signal handling in Linux</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Recently I ran into this problem. How do you capture SIGSEGV with a signal handler and still generate a core file?</p>
<p>The problem is that once you have your own signal handler for SIGSEGV, Linux will not call default signal handler which generates the core file. So, once you got SIGSEGV, consider all that useful information about about origin of the exception, lost.</p>
<p>Luckily, there&#8217;s a solution. Here&#8217;s what I did.</p>
<p>You start with registering a signal handler. Once you get the signal, inside of the signal handler, set signal handler for the signal to SIG_DFL. Then send yourself same signal, using <em>kill()</em> system call. Here&#8217;s a short code snippet that demonstrates this little trick in action.</p>
<pre class="brush:cpp">#include &lt;stdio.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;unistd.h&gt;
#include &lt;signal.h&gt;

void sighandler(int signum)
{
    printf("Process %d got signal %d\n", getpid(), signum);
    signal(signum, SIG_DFL);
    kill(getpid(), signum);
}

int main()
{
    signal(SIGSEGV, sighandler);
    printf("Process %d waits for someone to send it SIGSEGV\n",
        getpid());
    sleep(1000);

    return 0;
}</pre>
<p>Note that this code doesn&#8217;t actually cause a segmentation fault. To simulate segmentation fault, I did <em>kill -11 &lt;pid&gt;</em> from the command line. This is what happened.</p>
<pre>$ ls
sigs.c
$ gcc sigs.c
$ ./a.out
Process 2149 waits for someone to send it SIGSEGV
Process 2149 got signal 11
Segmentation fault (core dumped)
$ ls
a.out*  core  sigs.c</pre>
<p>Obviously, without lines 9 and 10 in the code, there would not be core file.</p>
<p>By the way, you can use this technique to handle any core generating exception &#8211; SIGILL, SIGFPE, etc.</p>
<p>Related posts:<ol>
<li><a href='http://www.alexonlinux.com/signal-handling-in-linux' rel='bookmark' title='Signal handling in Linux'>Signal handling in Linux</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/how-to-handle-sigsegv-but-also-generate-core-dump/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>How to obtain a unique thread identifier on Linux</title>
		<link>http://www.alexonlinux.com/how-to-obtain-unique-thread-identifier-on-linux</link>
		<comments>http://www.alexonlinux.com/how-to-obtain-unique-thread-identifier-on-linux#comments</comments>
		<pubDate>Tue, 25 Mar 2008 19:35:18 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[call]]></category>
		<category><![CDATA[getpid]]></category>
		<category><![CDATA[gettid]]></category>
		<category><![CDATA[identifier]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[pid]]></category>
		<category><![CDATA[posix]]></category>
		<category><![CDATA[pthread]]></category>
		<category><![CDATA[syscall]]></category>
		<category><![CDATA[system]]></category>
		<category><![CDATA[thread]]></category>
		<category><![CDATA[tid]]></category>

		<guid isPermaLink="false">http://www.alexandersandler.net/short-articles/how-to-obtain-unique-thread-identifier-on-linux</guid>
		<description><![CDATA[From some reason this topic never got enough attention in libc. POSIX threads library does addresses this issue, however what starts in POSIX library stays in POSIX library. pthread_self() and friends will get you an identifier that is unique accross your program, but not accross your system. Although thread is a system object, the system [...]
Related posts:<ol>
<li><a href='http://www.alexonlinux.com/signal-handling-in-linux' rel='bookmark' title='Signal handling in Linux'>Signal handling in Linux</a></li>
<li><a href='http://www.alexonlinux.com/pthread-spinlocks' rel='bookmark' title='pthread spinlocks'>pthread spinlocks</a></li>
<li><a href='http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock' rel='bookmark' title='pthread mutex vs pthread spinlock'>pthread mutex vs pthread spinlock</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img class="HeaderImage alignleft" style="width: 128px; height: 93px;" src="http://www.alexandersandler.net/wp-content/uploads/2008/03/threadid.thumbnail.jpg" alt="Thread ID" width="128" height="93" /> From some reason this topic never got enough attention in libc. POSIX threads library does addresses this issue, however what starts in POSIX library stays in POSIX library. <em>pthread_self()</em> and friends will get you an identifier that is unique accross your program, but not accross your system. Although thread is a system object, the system is unaware of the identifier POSIX library allocated for the thread. Thus the thread identifier allocated by the POSIX library does identify your thread within boundaries of your program, yet every-one else knows nothing about this identifier and its meaning.</p>
<p><span id="more-77"></span> On the contrary, Linux identifies threads with PID like number called TID. These numbers are system-wide. Tools like <em>htop</em> understand them and allow you to obtain information for each and every thread.</p>
<p>In Linux, there&#8217;s a system call that will return a TID of calling thread. The name of the system call is <em>gettid()</em>. From some reason it is not implemented in <em>glibc</em>. Probably it is because it is Linux specific system call. Anyway you have to use <em>syscall()</em> to call it. Here&#8217;s a sample code that does exactly this.</p>
<pre class="brush:cpp">#include &lt;stdio.h&gt;
#include &lt;linux/unistd.h&gt;
#include &lt;sys/syscall.h&gt;
#include &lt;unistd.h&gt;

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

int main()
{
        printf( "My TID is %d\n", (int)gettid() );
        return 0;
}</pre>
<p>Related posts:<ol>
<li><a href='http://www.alexonlinux.com/signal-handling-in-linux' rel='bookmark' title='Signal handling in Linux'>Signal handling in Linux</a></li>
<li><a href='http://www.alexonlinux.com/pthread-spinlocks' rel='bookmark' title='pthread spinlocks'>pthread spinlocks</a></li>
<li><a href='http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock' rel='bookmark' title='pthread mutex vs pthread spinlock'>pthread mutex vs pthread spinlock</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/how-to-obtain-unique-thread-identifier-on-linux/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

