<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Simple Computer Problems!</title>
	<atom:link href="http://scproblems.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://scproblems.wordpress.com</link>
	<description>Simple ..but tantalizingly hard to solve sometimes....!</description>
	<lastBuildDate>Fri, 01 May 2009 14:15:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='scproblems.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>The Simple Computer Problems!</title>
		<link>http://scproblems.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://scproblems.wordpress.com/osd.xml" title="The Simple Computer Problems!" />
	<atom:link rel='hub' href='http://scproblems.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Memory Usage Monitor</title>
		<link>http://scproblems.wordpress.com/2009/03/23/memory-usage-monitor/</link>
		<comments>http://scproblems.wordpress.com/2009/03/23/memory-usage-monitor/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 18:56:42 +0000</pubDate>
		<dc:creator>prajjwald</dc:creator>
				<category><![CDATA[freezes]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://scproblems.wordpress.com/?p=12</guid>
		<description><![CDATA[This problem was certainly irritating! I had come to work one day, when I found out that one of the main servers for a lab had crashed without explanation the day before, leading to temporary chaos.  The only pointers present were that there were some kernel segfaults recorded in /var/log/messages.  However, the system had crashed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scproblems.wordpress.com&amp;blog=4983138&amp;post=12&amp;subd=scproblems&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This problem was certainly irritating! I had come to work one day, when I found out that one of the main servers for a lab had crashed without explanation the day before, leading to temporary chaos.  The only pointers present were that there were some kernel segfaults recorded in /var/log/messages.  However, the system had crashed at around 14:40, while thlast segfault was at 13:55 or similar (writing this part out of memory, and don&#8217;t feel like going back to the server logs right now).</p>
<p>I looked at the sar output, and figured out that the kernel segfaults were in fact, quite possibly the culprit.  Right around the time of the segfaults, the memory usage started picking up rapidly, and eventually, page faults went up too like crazy.  I would like to quote figures, but since I would have to bring up the stats again, and I am kind of a lazy guy, I prefer not to right now.</p>
<p>The kernel logs did show the program that was responsible: a.out <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> .  Fortunately, there was only one recent a.out on the server (more users than developers), and I located the writer of the buggy program.  He had a memory leak, and was running his programs, which would segfault, and he would be wondering why the server crashed.  I explained, and his supervisor came in, asking for a memory monitor that would kill processes hogging up more than a certain amount of memory.</p>
<p>I preferred the other solution: them writing a wrapper around their test programs to make sure memory leaks were handled properly (on top of that, I hate server crashing work on production servers).  However, since I was pressured a bit too much, and I hate having the server crash again, I googled for scripts to do that.  Couldn&#8217;t find any (and I am very sure there is a very good reason for that!!!).</p>
<p>Which led me to write my own python script to do that.  It might be a bit bloated for most purposes: it does logging and sends you email too&#8230; but I have not configured it to run in daemon mode yet (so you have to run it using nohup in the background).  Here goes:<BR></p>
<pre>
<font color="#8080ff">#!/usr/bin/python</font>
<font color="#8080ff">#Prajjwal Devkota</font>
<font color="#8080ff">#March 18, 2008</font>
<font color="#8080ff">#Script to kill processes that hog memory usage</font>

<font color="#8080ff">#Feature wishlist (</font><span style="background-color:#ffff00;"><font color="#808080">TODO</font></span><font color="#8080ff">):</font>
        <font color="#8080ff">#Trapping kill signals before exiting, and appropriately logging them (perhaps leave the KILL signal untrapped, but at least the softer kills should be trapped, and the -k and -r options in the program should call the softer KILL options</font>
        <font color="#8080ff">#Throttling for messages about processes above ALERT_THRESHOLD but below KILL_THRESHOLD</font>
        <font color="#8080ff">#Email functionality:</font>
                <font color="#8080ff">#Message specific subject lines</font>
                <font color="#8080ff">#Options to turn emailing on/off</font>
                <font color="#8080ff">#Options to send email only for specified types of log messages</font>
        <font color="#8080ff">#Startup/Shutdown/Reconfiguration options</font>
                <font color="#8080ff">#Built in daemon functionality: currently, you have to start it in 'daemon mode' by typing 'nohup mem_usage_monitor.py &amp;'</font>
                <font color="#8080ff">#Options for killing existing processes, and possibly, even doing a 'soft restart' <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </font>

<font color="#ff40ff">import</font> os
<font color="#ff40ff">import</font> commands
<font color="#ff40ff">import</font> time
<font color="#ff40ff">import</font> sys
<font color="#ff40ff">import</font> socket
<font color="#ff40ff">import</font> getopt

<font color="#8080ff">#programs and paths</font>
SENDMAIL = &quot;<font color="#ff6060">/usr/sbin/sendmail</font>&quot;

<font color="#8080ff">#Files</font>
PID_FILE=&quot;<font color="#ff6060">/var/run/mem_usage_monitor.pid</font>&quot;
PROC_MEM_FILE=&quot;<font color="#ff6060">/proc/meminfo</font>&quot;
LOG_FILE=&quot;<font color="#ff6060">/var/log/mem_usage_monitor.log</font>&quot;

<font color="#8080ff">#No email functionality as of now, but keeping it for when I add email notifications of misbehaving and killed processes</font>
MY_EMAIL=&quot;<font color="#ff6060">mem_monitor@</font>&quot;+socket.gethostname()
<font color="#8080ff">#Admin Email</font>
ADMIN_EMAIL=&quot;<font color="#ff6060">your_email@your.domain.com</font>&quot;
MAIL_SUBJECT=&quot;<font color="#ff6060">Alert from Memory Monitor on </font>&quot;+socket.gethostname()

<font color="#8080ff">#Alert if memory usage above 15% -- just in case multiple processes run, they have low priorities at least-- might help things a bit (though I doubt they will help much!)</font>
ALERT_PCNT_THRESHOLD=15
<font color="#8080ff">#Kill if memory usage above 90%</font>
KILL_PCNT_THRESHOLD=90

minute=60 <font color="#8080ff">#seconds</font>
hours=minute*60
<font color="#8080ff">#check every 10 seconds <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </font>
SLEEP_TIME=5

<font color="#8080ff">#End of settings... on to code</font>
<font color="#8080ff">#Modify below this line only if you know what you are doing </font>
<font color="#ffff00">def</font> <font color="#00ffff">read_memory_total</font>():
        exists=os.path.exists(PROC_MEM_FILE)
        <font color="#ffff00">if</font> exists:
                memfile=open(PROC_MEM_FILE)
                memtotalline=memfile.readline().strip()
                memfile.close()
                <font color="#ffff00">if</font> (memtotalline.split()[0]==&quot;<font color="#ff6060">MemTotal:</font>&quot;):
                        <font color="#ffff00">return</font> int(memtotalline.split()[1])
                <font color="#ffff00">else</font>:
                        <font color="#ffff00">print</font> PROC_MEM_FILE+&quot;<font color="#ff6060"> format seems to be different than what I expected!</font><font color="#ff40ff">\n</font><font color="#ff6060">...exiting</font>&quot;
                        <font color="#ffff00">print</font> &quot;<font color="#ff6060">First line encountered:</font><font color="#ff40ff">\n</font>&quot;+memtotalline+&quot;<font color="#ff40ff">\n</font>&quot;
                        sys.exit(2)
        <font color="#ffff00">else</font>:
                <font color="#ffff00">print</font> &quot;<font color="#ff6060">Could not find </font>&quot;+PROC_MEM_FILE+&quot;<font color="#ff40ff">\n</font><font color="#ff6060">...exiting</font>&quot;
                sys.exit(3)

<font color="#ffff00">def</font> <font color="#00ffff">check_if_already_running</font>():
        exists=os.path.exists(PID_FILE)
        <font color="#ffff00">if</font> exists:
                 pidhandle=open(PID_FILE)
                 daemon_pid=pidhandle.readline().strip()
                 pidhandle.close()
                 ps_output=commands.getoutput('<font color="#ff6060">ps -p </font>'+daemon_pid).splitlines()
                 <font color="#ffff00">if</font> (len(ps_output)==1):
                        exists=False
                        <font color="#ffff00">print</font> &quot;<font color="#ff6060">pid file found, but pid </font>&quot;+daemon_pid+&quot;<font color="#ff6060"> not running</font>&quot;
                 <font color="#ffff00">else</font>:
                        <font color="#ffff00">if</font> (restart_existing):
                                commands.getoutput('<font color="#ff6060">kill </font>' + daemon_pid)
                                exists=False
                        <font color="#ffff00">else</font>:
                                <font color="#ffff00">print</font> &quot;<font color="#ff6060">process already seems to be running with pid of </font>&quot;+daemon_pid
                                <font color="#ffff00">print</font> &quot;<font color="#ff6060">Use '-r' switch to kill existing process and start new one</font>&quot;
        <font color="#ffff00">else</font>:
                <font color="#ffff00">print</font> &quot;<font color="#ff6060">No pid file found</font>&quot;
        <font color="#ffff00">return</font> exists

<font color="#ffff00">def</font> <font color="#00ffff">opt_parse</font>(arguments):
    <font color="#ffff00">global</font> restart_existing
    <font color="#ffff00">try</font>:
        <font color="#8080ff">#opts, args = getopt.getopt(sys.argv[1:], &quot;ho:v&quot;, [&quot;help&quot;, &quot;output=&quot;])</font>
        opts, args = getopt.getopt(arguments, &quot;<font color="#ff6060">r</font>&quot;, [&quot;<font color="#ff6060">restart</font>&quot;])
    <font color="#ffff00">except</font> getopt.GetoptError, err:
        <font color="#8080ff"># print help information and exit:</font>
        <font color="#ffff00">print</font> str(err) <font color="#8080ff"># will print something like &quot;option -a not recognized&quot;</font>
        sys.exit(2)
    <font color="#ffff00">for</font> option, argument <font color="#ffff00">in</font> opts:
        <font color="#ffff00">if</font> option == &quot;<font color="#ff6060">-r</font>&quot;:
            restart_existing = True
        <font color="#ffff00">else</font>:
            <font color="#ffff00">assert</font> False, &quot;<font color="#ff6060">unhandled option</font>&quot;

<font color="#ffff00">def</font> <font color="#00ffff">email_admins</font>(line):
        <font color="#ffff00">global</font> SENDMAIL,MY_EMAIL,ADMIN_EMAIL
        <font color="#8080ff"># open a pipe to the mail program and write the data to the pipe</font>
        mailpipe = os.popen(&quot;<font color="#ff6060">%s -t</font>&quot; % SENDMAIL, '<font color="#ff6060">w</font>')
        header=&quot;<font color="#ff6060">From: </font>&quot;+MY_EMAIL+&quot;<font color="#ff40ff">\n</font><font color="#ff6060">To: </font>&quot;+ADMIN_EMAIL+&quot;<font color="#ff40ff">\n</font><font color="#ff6060">Return-Path: </font>&quot;+MY_EMAIL+&quot;<font color="#ff40ff">\n</font><font color="#ff6060">Subject: </font>&quot;+MAIL_SUBJECT+&quot;<font color="#ff40ff">\n\n</font>&quot;
        mailpipe.write(header+line)
        <font color="#8080ff">#print header+line</font>
        exitcode = mailpipe.close()
        <font color="#ffff00">if</font> exitcode:
            <font color="#ffff00">print</font> &quot;<font color="#ff6060">Mail sending was not successful: %s</font>&quot; % exitcode

<font color="#ffff00">def</font> <font color="#00ffff">log_write</font>(line,email=True):
        <font color="#ffff00">global</font> logfile
        write_string=time.strftime(&quot;<font color="#ff6060">%h %d %y %X</font>&quot;)+&quot;<font color="#ff6060">: </font>&quot;+line+&quot;<font color="#ff40ff">\n</font>&quot;
        logfile.write(write_string)
        logfile.flush()
        <font color="#ffff00">if</font> email:
                email_admins(write_string)

TOTALSYSMEM=read_memory_total()

<font color="#8080ff">#GB in terms of KB</font>
GB=1024*1024
<font color="#8080ff">#ALERT_THRESHOLD=2.5*GB</font>
ALERT_THRESHOLD=(TOTALSYSMEM*ALERT_PCNT_THRESHOLD/100)
KILL_THRESHOLD=(TOTALSYSMEM*KILL_PCNT_THRESHOLD/100)
<font color="#8080ff">#Kill and restart already running process if present?</font>
restart_existing=False

arguments=sys.argv[1:]
opt_parse(arguments)

already_running=check_if_already_running()
<font color="#ffff00">if</font> already_running:
        <font color="#ffff00">print</font> &quot;<font color="#ff6060">Exiting!</font>&quot;
        sys.exit(1)
<font color="#ffff00">else</font>:
        <font color="#ffff00">print</font> &quot;<font color="#ff6060">Starting new process with pid </font>&quot;+str(os.getpid())
        pidhandle=open(PID_FILE,'<font color="#ff6060">w</font>')
        pidhandle.write(str(os.getpid())+&quot;<font color="#ff40ff">\n</font>&quot;)
        pidhandle.write(&quot;<font color="#ff6060">SLEEP_TIME: </font>&quot;+str(SLEEP_TIME)+&quot;<font color="#ff40ff">\t</font><font color="#ff6060">ALERT_THRESHOLD: </font>&quot;+str(ALERT_THRESHOLD)+&quot;<font color="#ff40ff">\t</font><font color="#ff6060">KILL_THRESHOLD: </font>&quot;+str(KILL_THRESHOLD)+&quot;<font color="#ff40ff">\n</font>&quot;)
        pidhandle.close()

logfile=open(LOG_FILE,'<font color="#ff6060">a</font>')

<font color="#ffff00">print</font> &quot;<font color="#ff6060">SLEEP_TIME: </font>&quot;+str(SLEEP_TIME)+&quot;<font color="#ff6060">s</font><font color="#ff40ff">\t</font><font color="#ff6060">ALERT_THRESHOLD: </font>&quot;+str(ALERT_THRESHOLD)+&quot;<font color="#ff6060">kb</font><font color="#ff40ff">\t</font><font color="#ff6060">KILL_THRESHOLD: </font>&quot;+str(KILL_THRESHOLD)+&quot;<font color="#ff6060">kb</font>&quot;

<font color="#8080ff">#Enable this for default startup so that you know if someone has been messing around!</font>
log_write(&quot;<font color="#ff6060">Memory Monitor started with:</font><font color="#ff40ff">\n\t</font><font color="#ff6060">SLEEP_TIME: </font>&quot;+str(SLEEP_TIME)+&quot;<font color="#ff6060">s</font><font color="#ff40ff">\t</font><font color="#ff6060">ALERT_THRESHOLD: </font>&quot;+str(ALERT_THRESHOLD)+&quot;<font color="#ff6060">kb</font><font color="#ff40ff">\t</font><font color="#ff6060">KILL_THRESHOLD: </font>&quot;+str(KILL_THRESHOLD)+&quot;<font color="#ff6060">kb</font>&quot;)

<font color="#8080ff">#Enable this line instead of the previous one if you don't want to receive emails about the program starting up</font>
<font color="#8080ff">#while tuning parameters, you probably don't want to get as many emails!</font>
<font color="#8080ff">#log_write(&quot;Memory Monitor started with:\n\tSLEEP_TIME: &quot;+str(SLEEP_TIME)+&quot;s\tALERT_THRESHOLD: &quot;+str(ALERT_THRESHOLD)+&quot;kb\tKILL_THRESHOLD: &quot;+str(KILL_THRESHOLD)+&quot;kb&quot;,False)</font>

<font color="#8080ff">#List of pids that have already been noted for showing attitude problems in the previous iteration</font>
bad_pids=[]
<font color="#ffff00">print</font> len(bad_pids)

<font color="#ffff00">while</font> 1:
        <font color="#8080ff">#List of new bad pids that will eventually replace the existing bad pids</font>
        new_bad_pids=[]
        ps_output=commands.getoutput('<font color="#ff6060">ps -eo pid,size,vsize,suser,cmd --sort -vsize</font>').splitlines()
        <font color="#ffff00">for</font> process_line_raw <font color="#ffff00">in</font> ps_output[1:11]:
                process_line=process_line_raw.strip().split()
                pid=int(process_line[0])
                size=process_line[1]
                vsize=int(process_line[2])
                user=process_line[3]
                cmd=process_line[4]
                pinfo=&quot;<font color="#ff6060">Running user: </font>&quot;+user+&quot;<font color="#ff40ff">\t</font><font color="#ff6060">process name: </font>&quot;+cmd+&quot;<font color="#ff40ff">\t</font><font color="#ff6060">pid:</font>&quot;+str(pid)+&quot;<font color="#ff40ff">\t</font><font color="#ff6060">memory used: </font>&quot;+str(vsize)
                <font color="#ffff00">if</font> (vsize &gt;= KILL_THRESHOLD):
                        log_write(&quot;<font color="#ff6060">Alert: Process stepped over memory usage limit, going to kill it: </font>&quot;+pinfo)
                        <font color="#ffff00">print</font> &quot;<font color="#ff6060">silence </font>&quot;+str(pid)+&quot;<font color="#ff6060">: I kill you!</font>&quot;
                        <font color="#8080ff">#Forceful kill if we reach this stage!</font>
                        commands.getoutput('<font color="#ff6060">kill -9 </font>' + str(pid))
                <font color="#ffff00">elif</font> (vsize &gt;= ALERT_THRESHOLD):
                        ALREADY_CONVICTED=False
                        <font color="#8080ff">#print &quot;bad_pids:&quot;</font>
                        <font color="#8080ff">#print bad_pids</font>
                        badpid_index=0
                        <font color="#ffff00">while</font> ((<font color="#ffff00">not</font> ALREADY_CONVICTED) <font color="#ffff00">and</font> (badpid_index &lt; len(bad_pids))):
                                <font color="#8080ff">#if (pid &lt; bad_pids[badpid_index]):</font>
                                <font color="#8080ff">#   break</font>
                                <font color="#8080ff">#elif (pid == bad_pids[badpid_index]):</font>
                                <font color="#ffff00">if</font> (pid == bad_pids[badpid_index]):
                                        ALREADY_CONVICTED=True
                                badpid_index=badpid_index+1
                        <font color="#ffff00">if</font> (<font color="#ffff00">not</font> ALREADY_CONVICTED):
                                commands.getoutput(&quot;<font color="#ff6060">ionice -c3 -p</font>&quot;+str(pid))
                                commands.getoutput(&quot;<font color="#ff6060">renice +20 </font>&quot;+str(pid))
                                log_write(&quot;<font color="#ff6060">Alert: Process showing bad attitude problems, reducing i/o and cpu priority!: </font>&quot;+pinfo,False)
                        <font color="#8080ff">#Add the bad pid to the new list of bad pids in any case</font>
                        new_bad_pids.append(pid)
        <font color="#8080ff">#new_bad_pids.sort()</font>
        bad_pids=new_bad_pids
        time.sleep(SLEEP_TIME)
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scproblems.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scproblems.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scproblems.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scproblems.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scproblems.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scproblems.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scproblems.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scproblems.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scproblems.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scproblems.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scproblems.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scproblems.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scproblems.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scproblems.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scproblems.wordpress.com&amp;blog=4983138&amp;post=12&amp;subd=scproblems&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scproblems.wordpress.com/2009/03/23/memory-usage-monitor/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/30413fdea8dd2db6bde0a0ca4f4b71db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">P</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting started with gdb</title>
		<link>http://scproblems.wordpress.com/2008/10/09/getting-started-with-gdb/</link>
		<comments>http://scproblems.wordpress.com/2008/10/09/getting-started-with-gdb/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 19:42:29 +0000</pubDate>
		<dc:creator>prajjwald</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://scproblems.wordpress.com/?p=8</guid>
		<description><![CDATA[I found these steps helpful a few weeks ago: 1. Compile your program with the -g switch so that gcc/g++ builds it with debugging options. e.g. gcc -g myprog.cc -omyprog 2. Run gdb with the binary as an argument gdb myprog 3. Check the contents of the program list &#8211; type enter till you reach [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scproblems.wordpress.com&amp;blog=4983138&amp;post=8&amp;subd=scproblems&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I found these steps helpful a few weeks ago:</p>
<p>1. Compile your program with the -g switch so that gcc/g++ builds it with debugging options.</p>
<p>e.g. gcc -g myprog.cc -omyprog</p>
<p>2. Run gdb with the binary as an argument</p>
<p>gdb myprog</p>
<p>3. Check the contents of the program</p>
<p>list</p>
<p>&#8211; type enter till you reach the end of the program.</p>
<p>4. Put breakpoints, if required</p>
<p>e.g. break 4 (put a break in line 4)  &#8212; can elaborate more on that, will leave it as it is for now.</p>
<p>5. Run your program (with arguments, if necessary).</p>
<p>run (put arguments after run if required by your program).</p>
<p>6. examine values:</p>
<p>listing a few I remember off the top of my head:</p>
<p>x/s variable name&#8211; display contents of string</p>
<p>x/32xw $esp &#8212; show contents of the location pointed to by esp, and 32 locations before (or is it after.. hehe.. gotta check!)</p>
<p>and so on&#8230; help will inform you better than I will (at least for now!).</p>
<p>7. Step on to the next breakpoint:</p>
<p>step</p>
<p>8. Repeat steps 6 and 7 till either the program gracefully exits, you get bored, or it segfaults (or does other nasty stuff).</p>
<p>9. check the various registers, eip, etc if the program segfaulted or did nasty stuff.</p>
<p>If you want to debug the core dump of a program, do:</p>
<p>gdb program_name core</p>
<p>(make sure the core file is there first!)</p>
<p>I just recall one command for now (limited experience with gdb <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ):</p>
<p>where</p>
<p>this should give you an idea of where exactly the program segfaulted (if it did).</p>
<p>Check <a title="this page" href="http://www.faqs.org/docs/ldev/0130091154_159.htm" target="_blank">this page</a> for more information</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scproblems.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scproblems.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scproblems.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scproblems.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scproblems.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scproblems.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scproblems.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scproblems.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scproblems.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scproblems.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scproblems.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scproblems.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scproblems.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scproblems.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scproblems.wordpress.com&amp;blog=4983138&amp;post=8&amp;subd=scproblems&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scproblems.wordpress.com/2008/10/09/getting-started-with-gdb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/30413fdea8dd2db6bde0a0ca4f4b71db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">P</media:title>
		</media:content>
	</item>
		<item>
		<title>GDB seems cool :)</title>
		<link>http://scproblems.wordpress.com/2008/10/07/gdb-seems-cool/</link>
		<comments>http://scproblems.wordpress.com/2008/10/07/gdb-seems-cool/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 01:03:21 +0000</pubDate>
		<dc:creator>prajjwald</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://scproblems.wordpress.com/?p=6</guid>
		<description><![CDATA[For those people who have had to program in Linux like I have had to (that is.. because of coursework), and if you have been used to a development environment like Visual C++ (I was used to something much more basic, but I found it very easy nonetheless&#8211; Turbo Pascal!), you might find debugging in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scproblems.wordpress.com&amp;blog=4983138&amp;post=6&amp;subd=scproblems&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For those people who have had to program in Linux like I have had to (that is.. because of coursework), and if you have been used to a development environment like Visual C++ (I was used to something much more basic, but I found it very easy nonetheless&#8211; Turbo Pascal!), you might find debugging in linux a lot more difficult, especially if you start getting segfaults.</p>
<p>Something I learned very recently: use gdb.. it helps a lot!  I just managed to discover a very subtle error in my own code that was causing my program to crash using it&#8230;  google around a bit, catch hold of a good gdb tutorial, and debug away.. don&#8217;t let the black screen scare you.. believe me.. if you have to program in LInux (even if its just coursework), gdb might be well worth the effort (30-60 mins max?) if you have to spawn more than a few hundred lines of code and debug it too!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scproblems.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scproblems.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scproblems.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scproblems.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scproblems.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scproblems.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scproblems.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scproblems.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scproblems.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scproblems.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scproblems.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scproblems.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scproblems.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scproblems.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scproblems.wordpress.com&amp;blog=4983138&amp;post=6&amp;subd=scproblems&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scproblems.wordpress.com/2008/10/07/gdb-seems-cool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/30413fdea8dd2db6bde0a0ca4f4b71db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">P</media:title>
		</media:content>
	</item>
		<item>
		<title>Is your computer freezing up on you?</title>
		<link>http://scproblems.wordpress.com/2008/09/26/is-your-computer-freezing-up-on-you/</link>
		<comments>http://scproblems.wordpress.com/2008/09/26/is-your-computer-freezing-up-on-you/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 00:52:25 +0000</pubDate>
		<dc:creator>prajjwald</dc:creator>
				<category><![CDATA[filesystem corruption]]></category>
		<category><![CDATA[freezes]]></category>
		<category><![CDATA[windows xp]]></category>
		<category><![CDATA[computer problems]]></category>

		<guid isPermaLink="false">http://scproblems.wordpress.com/?p=3</guid>
		<description><![CDATA[The windows xp machine I had been using had been freezing up on me more and more frequently for the past few days.  I had booted over to Linux and checked the smart statistics of the hard disk– which seemed to be fine.  I was thinking of doing memory tests too.. but never got around [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scproblems.wordpress.com&amp;blog=4983138&amp;post=3&amp;subd=scproblems&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The windows xp machine I had been using had been freezing up on me more and more frequently for the past few days.  I had booted over to Linux and checked the smart statistics of the hard disk– which seemed to be fine.  I was thinking of doing memory tests too.. but never got around to it (since I was working on Linux anyways).  I was not sure what was causing the freezes– I suspected a corrupted driver or (God forbid!) a virus/malware program.</p>
<p>I was using ntfs-3g to mount the ntfs partition I had my data on on Linux, and when I ran an updatedb command, I suddenly got all these ‘io error’ messages for some symantec files.  I had been guessing that Windows would automatically notice a corrupted partition and do chkdsk.. maybe I had skipped disk checking sometime after an unclean shutdown (power failure).</p>
<p>Suspecting a corrupted filesystem, I booted to Windows XP safe mode, ran chkdsk /f c:, scheduled the check to be run at boot, and voila.. after the error-fixing, my computer seems to have started liking me once again.. no more freezes every 10 minutes!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scproblems.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scproblems.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scproblems.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scproblems.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scproblems.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scproblems.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scproblems.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scproblems.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scproblems.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scproblems.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scproblems.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scproblems.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scproblems.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scproblems.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scproblems.wordpress.com&amp;blog=4983138&amp;post=3&amp;subd=scproblems&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scproblems.wordpress.com/2008/09/26/is-your-computer-freezing-up-on-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/30413fdea8dd2db6bde0a0ca4f4b71db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">P</media:title>
		</media:content>
	</item>
	</channel>
</rss>
