An updated edition – dbx-cheatsheet-solaris1.pdf.
Monthly Archives: May 2007
Dbx cheat sheet – Solaris
I created a small cheat sheet for dbx on Solaris. Actually I’m working on a longer tutorial about debugging on Solaris – this was a slight detour. You can find the pdf here dbx-cheatsheet-solaris1.pdf – the export from Google docs wasn’t as nice as I thought it would be. Maybe I’ll stick to Openoffice for a while.
Formatted output – printf
This is the piece of code I saw today:
printf ("%.*s\n",l,s);
This is the same as
printf ("%.2s\n",s); //l=2 in my example.
I suppose everyone knows this, and I’m the only idiot! Rather nice, when you don’t know before hand what width you want to print. I clearly need to go back to K&R.
System information on Solaris, the programmatic way
Again, work in progress. But at this point I think I have got everything I’m interested in at the moment.
The root node in solaris_proc.pdf has two childern – one is about getting process information from /proc and the other is about getting system information using libkstat.
Please email/reply to this post in case there are any corrections!
/proc on Linux
Trying to understand the different values in /proc .. 2.6 kernel. This (linux_proc.jpeg) is by no means complete – I’m still working on it. I suppose I should use some other format than freemind, but I want to eventually group different files under /proc according to type – e.g., all io device information under one node. Hopefully it will still make sense then!
Edit: the /proc/<pid>/stat seems to have changed from 2.6.10 to 2.6.20. Will post an updated and corrected document soon.
Using vimdiff
I’ve been using meld so far – but that is cumbersome if you are working on a remote machine. vimdiff is miles better in such cases:
“vimdiff file1 file2” or “vimdiff file1 file2 file3”
Move between panes with ‘ctrl-w‘ and left or right arrow keys. And you can yank/paste etc. between panes as well. Huzzah!
C puzzle – 1
Today it’s a C puzzle day – I got foxed at one of the questions my friend threw at me so decided to hunt up and practice some C puzzles. At worst, it will prepare me for interviews 🙂
This one is from GowriKumar’s website.
#include<stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16};
int main()
{
int d;
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
printf("%dn",array[d+1]);
return 0;
}
The usual, what’s wrong. This was straightforward, and involves understanding type promotion – something I mentioned before. The reason I put it here is: I read somewhere that I can make the preprocessor create the type I wanted – by doing something like this.
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))UL
This is supposed to make the compiler treat it as an unsigned long. So I wanted to find out what I should use for signed int. Well, I haven’t figured that out and UL didn’t work either – so I finally cast it as usual:
#define TOTAL_ELEMENTS (int) (sizeof(array) / sizeof(array[0]))
Bleargh – someone tell me why UL doesn’t work. It’s clearly mentioned here.
I’m using gcc 4.1.2.