Posts

Showing posts with the label Linux

Understanding Java Memory Model

I was browsing through the Linux kernel documentation and came across this excellent documentation on Memory Barriers . I was able to relate many of the concepts explained in this document with the issues that used to exist in the older buggy JVMs. I would strongly recommend to anyone to go through this kernel document to easily understand the 1.5+ Java Memory Model, especially the concept of happens-before ordering. The same author has written another excellent paper "Memory Barriers: a Hardware View for Software Hackers" , which covers the same topic in a bit more depth. Paul McKenney and David Howells - thanks a lot for your excellent document that helped me understand the key concepts behind memory barriers.

Reloading inittab without reboot

Use " /sbin/init q " if you made any changes to the inittab file and would like init to reload that file.

Ubuntu from USB drive

I wanted to try out running Ubuntu from my USB drive (2GB). While I was searching for the right software, I came across UNetbootin utility. This utility is a lot simpler to use than the method provided in the Ubuntu site , a method that makes use of Win32 disk imager. The best part is, UNetbootin provides you options to create bootables from other operating systems like FreeBSD, NetBSD and other notable flavors of Linux. UNetbootin is not an installable, its just one .exe file. You download the exe file and start it. It will prompt you for the version of OS you would like to burn in your USB. Once you select, it will automatically download the ISO image file and burn it for you. In case you happen to have the ISO image file available on your local hard drive, you can provide that path too.

bashreduce - a MapReduce system using command line tools

I came across this interesting reading in Linux Magazine about bashreduce . Sounds interesting. You will also find it useful to read about Richard Crowley's extensions to bashreduce .

KSplice - Thats what I had been looking for

The time has come to apply any critical kernel patches without rebooting the system. The tool that does this magic is called ksplice and shipped as a part of Ubuntu system (Jaunty). It would be a valuable part of any system that cannot afford to take a downtime. To learn more about ksplice, please read this Linux Magazine article .

Saving a file being viewed in less

Sometimes I have a long sequence of command line pipes that end in less command. For e.g. cvs log main.c | egrep "^revision " | less So what is the best way to save the contents that are being viewed in less? You cannot view those contents by typing the letter "v". If you do so you will get an error message saying "Cannot edit standard input (press RETURN)". The solution is simple. First type "g" to go to the beginning of the file. Then type "|". Then you will be prompted for the "mark:" and enter "$" (which denotes the end of file). Then you can enter a command for which the entire contents of less will be piped. For e.g. I will give the following: cat > /tmp/savefile.txt Thats it! You have saved the contents to the file /tmp/savefile.txt. Now you have a problem. Since you have moved to the beginning of the contents, you might want to go back to the same place where you were before saving the contents. Just typ...

Strace and defunct processes

We have a web application running in Tomcat. Today I ran into an issue that the web application started throwing some errors during start up. I wanted to figure what the application reads during the start up. So I started the whole Tomcat under strace , and started to analyze the strace output. Once I figured what was happening, I tried to stop strace with Ctrl-C, but it won't stop. So, I killed it with "kill -9". The strace is dead, but the Java process that was being traced went into a defunct state. This is what I was seeing when I did a "ps aux": 9929 1932 0.0 0.0 0 0 pts/0 Z 16:53 0:03 [java <defunct>] Hmm ... Not good! I tried to kill this process with "kill -9", but it won't work. If I try to start another instance of Tomcat, it complains that the port 8989, where it was supposed to listen, was already in use. But if I try to do a "netstat -pan", I couldn't find any process listening in that port eit...

You cannot do SMP in VMWare Player

VMWare player doesn't support SMP, though you might see a processor which is capable of SMP. Here is a quote from the VMWarePlayer manual : Virtual SMP VMware Player does not support Virtual SMP™. You cannot use VMware virtual machine that has more than one virtual processor assigned. For e.g. when I look at /proc/cpuinfo, I am seeing only one processor though my VMWare Player emulates "Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz". When I inspect the boot messages, I realized that my Linux switch to uniprocessor configuration while booting: [ 7.135461] SMP alternatives: switching to UP code [ 7.135523] Freeing SMP alternatives: 11k freed So if you are trying to test any multithreaded appplication, beware that the results you will get in your VMWare Player's Linux and the real Linux will not be the same. Your VMWare Player's version is likely to give you worse results as its running in uniprocessor mode.

A useful tool to print the signals status

I have written a useful tool that will help in analyzing the signal disposition for a given process. It will take the list of PIDs as input and will print the signal disposition of that process in a readable form. For e.g. 5877: SigQ: 0/4096 5877: SigPnd: None (mask 0000000000000000) 5877: SigBlk: None (mask 0000000000000000) 5877: SigIgn: SIGHUP, SIGUSR2, SIGWINCH, SIGIO (mask 0000000030001002) 5877: SigCgt: SIGALRM (mask 0000000000004001) The first column is the PID and the second column is the disposition and the the third column is the list of signals in a readable form. It is a Python script. You can download that from here . By default, the script doesn't print the real-time signals. To force it, you can specify the -r option in the command line. Sometimes there are signals for which there is no name available (for e.g. Signal 0). If such is the case, it will simply say 'Signal X'. There is no option to print the signal status of all the threads under the given pr...

Identifying threads under a given process

This is quick note. The method to identify all the threads under a given process ID differs significantly between Linux kernel versions 2.4.x and 2.6.x. In case of 2.4.x kernel, you should look for process IDs that are prefixed with dot (".") under the /proc folder. All these PIDs correspond to threads. If you open the /proc/.X/status file , the number appearing against "Tgid:" is the PID of the process that this thread corresponds to. So there is no direct way to tell the list of all the threads undre a given PID. The only way you can get that list is to iterate through all the directories that begin with dot under /proc , and check the "Tgid:" to be matching the PID in question. In case of 2.6.x kernel, all you need to do is just to get the list of all the directories under /proc/PID/task . Each one of these IDs will correspond to one thread of the process. Also you will exactly know how many threads are there by checking the "Threads:" value...

Changing color schemes in vim

You can change the color scheme of vim by the following command: :color The list of available color schemes could be found under /usr/share/vim/vim63/colors/ (If you are using a different version of vim then vim63 might be different for you). If you see file called blue.vim under this directory, to make use of that color scheme, you should give: :color blue If you would like to make the change permanent, add this line to your ~/.vimrc file.

Configuring the core file name pattern in Linux

First of all, you must make sure that you have set proper ulimit in your shell. You can check this by giving "ulimit -a" command. If the core file size is set to be 0, you can make it unlimited by giving "ulimit -c unlimited" . Refer to your shell's man page to know how to set this. The child always inherits the ulimit from its parent process. You can configure your system such that when an application dumps core the name of the core file has some meaningful name instead of just the bare word core . There are two files you should modify under /proc/sys/kernel configure this. /proc/sys/kernel/core_pattern - This contains pattern of the core file name. The following patterns are allowed: %% output one '%' %p pid %u uid %g gid %s signal number %t UNIX time of dump %h hostname %e executable filename /proc/sys/kernel/core_uses_pid - If this file contain...

Customizing the colors in ls output

This posting is specific to customizing the dircolors in bash shell in Linux. It may or may not be applicable to other shells and other platforms. When the bash shell is started, it executes all the shell scripts under the directory /etc/profile.d/ *.sh . You might find other shell scripts under this directory (for e.g. colorls .csh ), but those scripts are not to be executed by the bash shell. These files are executed within the current shell's environment, not in a separate execed shell (like a dotshell). One of these files is colorsls.sh . A set of rules in colorls.sh search for the user specific dircolors file. This file could be any one of the ~/.dircolors, ~/.dircolors.$TERM, ~/.dir_colors or ~/.dir_colors.$TERM. In case the user has more then one of these files, whichever comes last will be taken. Let us stick to the convention of using ~/.dircolors file for our customization. It is very easy to create this file by giving the following command: dircolors --sh > ~/.dircolo...

Random notes on proc & process status

proc file system gives a view of the processes, including kernel, running in the Linux system. Writing into some of the files under /proc changes the state of the processes in memory. For e.g. you can change how much maximum shared memory you want the kernel to allow by changing the file /proc/sys/kernel/shmmax . This will take effect without rebooting the system, since it directly modifies the value of that particular kernel variable. But most of these changes are transient. Hence you will lose them when you reboot your system. You can examine the state of the process using proc file system. Each process running in the system will have an entry under /proc/pid , where pid is the process ID. There are good tutorials that explain about each entry under this directory. You can google for them. But I could not find explanation for some entries, particularly status file. Thats the objective of this blog. For a single-threaded process, you will find all the information about the state of t...

Starting X sessions in Cygwin

Question: "I want to have my Linux desktop in my Windows machine. I have installed Cygwin. How to do this?" Follow these steps: Start your Cygwin command shell. Give "xinit -- -clipboard" in the command line. You will see a bare X window show with a command prompt in it. You will also see something like "Cygwin/X - 0:0" on the left-top of the window. This tells you the display in which the X server is listening for incoming connections. Give "xhost +" in the command prompt. This is to let the server accept all the incoming connections. Remember: if you are concerned about the security, refer to the man page of xhost on how to give a list of hosts instead of wild card "+". Start an ssh connection to your Linux box. Once logged in, set the display variable. As per this example it would be "export DISPLAY=x.x.x.x:0.0" where x.x.x.x is the IP address of your Windows box. Start your Gnome session by giving "gnome-session"...

dsh - Distributed Shell

In one of the Linux Magazine articles, I came across this shell called dsh (Distributed Shell) . The name is a misnomer as it is actually not a shell. It is a wrapper to invoke shell commands using ssh (or any other configured shell) in different machines. Nevertheless, I think this tool would be of tremendous help when the same command is to be run in multiple machines, which is what most of the admins do often. An example given in the Linux Magazine article is to run last command in multiple machines to see the login/logout activity.