Wednesday, March 20, 2013

strace in Linux

I ran into a interesting blog about strace.

http://timetobleed.com/hello-world/

time command in Linux

When working on cs252 lab, I was confused by the meaning of the output of time command. By searching the web, something useful was found.

http://www.dirac.org/linux/time/

To summarize,

Real is wall clock time - time from start to finish of the call. This is all elapsed time including time slices used by other processed and time the process spends blocked (for example if it is waiting for I/O to complete).

User is the amount of CPU time spent in user-mode code (outside the kernel) within the process. This is only actual CPU time used in executing the process. Other processes and time the process spends blocked do not count towards this figure.

Sys is the amount of CPU time spent in the kernel within the process. This means executing CPU time spent in system calls within the kernel, as opposed to library code, which is still running in user-space. Like 'user', this is only CUP time used by the process.

The equation is
user + Sys will tell you how much actual CPU time your process used.

Saturday, March 2, 2013

Tutorial for regular expression

Find a very good tutorial for regular expression!

http://www.regular-expressions.info/quickstart.html

This is a quick start for regular expression. Within this article, there is also a detailed version.

Write script to login a remote machine

As a cs student, I have remotely login many times every day. The name of the remote machine is pretty long and my password is even longer. So I decided to do something.

Firstly, I wrote a scipt like this


#!/bin/bash
ssh username@machinename

Here, username stands for your login name and machinename represents the address of the remote machine.

By running this script, I saved a lot of time to type the long name of the machine. But, another question is I still have to enter the code after running the script. I searched the Internet, keygen seems to be a cool command for me.

http://www.debian-administration.org/articles/152

This website has detailed instructions about how to use keygen. For mac users, we have no ssh-copy-id command. I found an alternative way to copy the public key to the server. The command is

cat ~/cat ~/.ssh/id_rsa.pub | ssh username@machinename "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"


install Ctags and Taglist without root

Ctags and Taglist seem to be quite popular plugins for vim editor. Since I'm novice to Linux. It took me several hours to figure out how to configure them for my vim on the department machine. It's kind of tricky because I have no root right on that machine.

I mainly borrowed methods from the following three places,


http://www.thegeekstuff.com/2009/04/ctags-taglist-vi-vim-editor-as-sourece-code-browser/


This one intrigues my curiosity to try out Ctags and Taglist.


http://superuser.com/questions/66367/is-it-possible-to-install-ctags-without-root-privs


The above site introduces how to install Ctags without root.


http://vim-taglist.sourceforge.net/installation.html


The last one is for installing taglist without root.



The main idea of installing Ctags without root is to compile it by yourself and install it in your home directory.


First download Ctags from its webpage and type in the following commands.


$ tar zxf ctags-5.8.tar.gz

$ cd ctags-5.8
$ ./configure --prefix=$HOME
$ make && make install


This will compile and install ctags in your home directory. The resulting binary will be: $HOME/bin/ctags


That's all I did to make Ctags work in my vim. If it doesn't work for you. Just check the second webpage. I omitted several steps which seems not critical to me.

For the Taglist, just follow the instructions in the third page. I only finished the first step - download taglist.zip and uzip it to .vim folder and it works.

The first website contains detailed description about how to use Ctags and taglist in vim. Have fun!