zsh + tmux + vim = awesome

I have frequently switched between working on IDEs like IntelliJ and PyCharm to plain old command line. While I usually settled on working with bash and vim, I realized that there is a lot of cool tweaking that you can do, to make the overall development experience much more productive and awesome.

zsh is awesome!

First of all, lets come to the shell. I usually used to just go with bash, until I saw that zsh is way more loaded ( for instance cycling through your directory when you do cd, correction suggestions, … I am still discovering all the cool stuff, but here’s a great  HN discussion ). So I switched to using zsh as my default shell. I also was able to get a cool theme, by using the oh-my-zsh framework – which you should definitely checkout! The default ‘robbyrussell’ theme was good enough for me, I didn’t want anything too fancy that required me to add powerfonts / color schemes. But here’s how my shell prompt looks like. It basically prints out my directory, followed by which git branch I am currently on which is super useful. There’s other stuff that you can add to the right like your battery status, etc if interested.

Screen Shot 2016-04-03 at 12.06.14 AM

Making Vim more awesome!

While I definitely do not want to start another flame war on vim vs emacs, here’s my take. I used emacs initially and I really loved it. Being able to run the terminal from within the shell and gdb without doing anything special was super convenient. But a lot of my work requires ssh-ing to a bunch of different servers, and most of them don’t come with emacs installed. I figured that if I was using vim most of the time, I might as well use it all of the time, so that I could do the keystrokes quicker.

I have installed some really useful plugins and remapped some of the keys, and it has made working in vim a lot more efficient. I’ll include my vimrc at the bottom of the post. I use Vundle  for plugin management. I use the gruvbox dark theme, because it is nice and aesthetic and works right out of the box without needing to install new palettes. I found a lot of the plugins by looking at http://vimawesome.com/. Currently I have used these for working on C++. I am still tweaking vim for Python and Clojure. Basically with the right set of plugins, your vim is as powerful and much more light weight than any IDE – IntelliJ used to take some crazy amount of memory on my OS X.  I remapped C-d to easily switch between vim and the shell, and also have a mapping that makes sure that the current search term is always at the page centre. I am using a minimal set of plugins – NerdTree for directory navigation, Tagbar for quickly capturing the file structure ( needs to have ctags installed), Airline for getting a nice status line at the bottom, Syntastic that quickly highlights any compile time errors, similar to an IDE and a couple of others. I am yet to try YouCompleteMe for code completion, but it’s definitely on the top of my list.

One super useful feature in vim is that it allows opening files in different tabs, something I only discovered recently. Simply do :tabe <file> and the file will be opened in a new tab. It is very easy to cycle between tabs using gT. You can also directly jump to a tab i by using {i}gT. I installed Tabline, which is a nice plugin that adds a number to every tab title, making it much easier to jump to tabs directly.

Here’s the final effect:

Screen Shot 2016-04-03 at 1.08.01 AM

tmux saves the day!

Finally tmux! I was initially quite scared of using tmux – I thought it was too complicated for a noob like me, but it turns out that there are really very few keystrokes with which you can do most of the useful stuff. I prefer using tmux for splitting panes and stuff because that means that I can use it both on linux and OS X, unlike iterm.

The biggest advantage of tmux is definitely that it keeps all your sessions alive, exactly like you left them. No more worrying when you accidentally unplug the wifi cable, or snap your macbook shut. I typically find it very useful when building a large project, I can just come back in the next day and check on the build status by attaching back my session, or can attach and continue with my debugging, where I left off during the commute.

There are some other cool projects like tmuxinator, which will actually fire up various sessions for you,  tile your panes and keep everything ready for you each day! I haven’t had a chance to look at it so far, but that’s definitely something I want to try out


All in all I am definitely more productive with all these tweaks. If there are any plugins or tools that have served you well, I would be very excited to try those out, so do let me know. Finally here’s my vimrc:

set backspace=indent,eol,start
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=/Users/xyz/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'majutsushi/tagbar'
Plugin 'morhetz/gruvbox'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/syntastic' "Syntax checking hacks for vim, displays errors on left after save
Plugin 'luochen1990/rainbow'
Plugin 'terryma/vim-multiple-cursors' "Submlime multiple text selection
Plugin 'Raimondi/delimitMate' "Auto add dual quotes, parenthesis, brackets, etc.
Plugin 'mkitt/tabline.vim'
Plugin 'bling/vim-airline'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
" Brief help
" :PluginList – lists configured plugins
" :PluginInstall – installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo – searches for foo; append `!` to refresh local cache
" :PluginClean – confirms removal of unused plugins; append `!` to auto-approve removal
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
nmap <F8> :TagbarToggle<CR>
nmap <F10> :NERDTreeToggle<CR>
nmap <C-d> :sh<CR>
" emacs binding for begin and end
cnoremap <c-a> <home>
cnoremap <c-e> <end>
" Keep search matches in the middle of the window.
nnoremap n nzzzv
nnoremap N Nzzzv
set background=dark
colorscheme gruvbox
let g:rainbow_active = 1
:syntax on
:set laststatus=2
:set statusline=%F
:set cursorline
:set tags+=$OSCAR_HOME/tags
:set number
"Use spaces instead of tabs
set tabstop=2 softtabstop=2 expandtab shiftwidth=2

view raw


hosted with ❤ by GitHub

Segmentation and Paging in Linux

The goal of both paging and segmentation is ultimately the same – to provide a way to translate virtual or logical addresses into physical addresses, that actually exist in the RAM.


Segmentation in Linux is not really used as the main virtualization technique anymore, and is kept mainly as a relic from the past.

There is a segment register for the code and the data segment in the program, as well as a bunch of other segments, which we won’t discuss. But each of these segments are described by a segment descriptor which is an 8 byte  entity.  There is obviously a bunch of stuff in each segment descriptor, but it mainly has the base address for each segment, its bounds and so on. The list of all the segment descriptors is maintained by the kernel in the Global Descriptor Table (GDT).  There is 1 GDT per every processor.  The kernel can also use a per-process descriptor table also called the Local Descriptor Table (LDT),  but this is rarely used.

So how do we get to the segment descriptors? Each segment register stores a segment selector.  A segment selector is a 16 bit entity. The 2 LSBs stand for the Requested Privilege Level (RPL).  Clearly it can represent 4 different privilege levels. The privilege levels 0-2 are all considered to be kernel mode whereas  level 3 is considered to be user mode. Thus this provides an easy way to protect the user mode from performing kernel-mode operations. The next bit is either a 0 or 1 indicating whether we should be using a GDT or LDT. Finally the remaining 13 MSBs are an index into the GDT(LDT) for the segment descriptor corresponding to the segment. In practice though, it isn’t necessary to access the GDT each time we need to look up a segment descriptor. Whenever there is a context switch, the kernel will initialize the segment registers with the corresponding segment selectors for the new process. At the same time, there are also corresponding non-programmable registers that will store the segment descriptor for the segment. Thus the  GDT needs to be looked up just once, during the context switch.



Paging in linux just provides a means to translate the virtual page numbers (VPN) to the corresponding physical page numbers. The typical way to do this is to maintain a page table. A page table simply provides a mapping from each VPN to the corresponding PPN.  Unfortunately, even for 32 bit architectures, this would mean having 2^32 entries, in the main memory.

The CR3 register stores the base address of the page table. Obviously, since each process will have a different VPN -> PPN mapping, there is a separate page table for each process. Whenever there is a context switch, the kernel saves the CR3 for the process in its task_struct and restores the CR3 from the task_struct for the new process.

Thus in linux, a page table is usually multi-level. First let’s talk about 32 bit architectures.  In this case the CR3 register points to page directory, the page directory in turn points to the page table. Each VPN is thus split into 3 parts. The first 10 MS bits are the index into the page directory and the next 10 bits are an index into the page table. Finally the last 12 bits are the actual offset in the page.  In case of 64 bit architectures, there is even more level of indirection.


Hello World!

Welcome to my new blog! This is where I’ll blog about neat stuff I discover as I explore computer systems, though there might be a fair bit of overlap with other related areas that also interest me.

So I just managed to bag a free domain from namecheap, and it is : objdump.me

Why objdump ?

First of all let’s get clear on the name. I learnt about objdump regretfully quite late ( when I was interning at Amazon) and it than came back again while taking grad OS at UT Austin. This is a very neat shell command, that will show you the contents of your assembled code ( e.g. a.out ) in all the gory details, you can actually view the segments and all. Its pretty exciting. Jessica McKellar has a couple of very very useful blogposts that explain this in a fun exercise. Highly recommended :