Wednesday, December 22, 2004

ASP.NET 1.1 Application/Page Lifecycle

It's essential to understand the execution lifecycle of ASP.NET. There's probably been plenty written on this topic but I just want to do a quick exercise to make sure the order is correct. So I created a simple page with a user control, and traced each event inside Global.asax and page's code behind. Here's the result:
  1. Application_Start //Only occurs when application is loaded
  2. Application_Init //Only occurs when application is loaded
  3. Application_BeginRequest
  4. Application_AuthenticateRequest
  5. Session_Start
  6. Page_Control_Init
  7. Page_Init
  8. Page_Control_LoadViewState
  9. Page_ProcessPostData // In Poskback
  10. Page_Load
  11. Page_Control_Load
  12. Page_RaisePostBackEvent // In Postback
  13. Page_SaveViewState
  14. Page_Control_SaveViewState
  15. Page_Control_Render
  16. Page_Render
  17. Page_Control_Unload
  18. Page_Unload
Notice the order of control events and page events. Control's Init, Render, Unload events occur earlier than Page's equivalents, but control's Load and SaveViewState events come later than Page's.

Monday, November 15, 2004

Remove Hidden Folders Recursively in Windows

In a Windows XP machine there's a folder copied from a Unix machine which contains many useless and hidden .cache folders. Following script can delete all these hidden folders recursively in DOS command line:

C:\temp>for /f "tokens=* delims=" %x in ('dir /s /b /a:d *cache') do rd /s /q "%x"

Alternatively we can create .bat batch file so we can just click it to run the script, but the token needs to be changed from %x to %%x:

for /f "tokens=* delims=" %%x in ('dir /s /b /a:d *cache') do rd /s /q "%%x"

Friday, November 12, 2004

C# vs Java

C# syntax is very similar to Java. Most noticeable ones to me are following ( based on C# 1.0 and Java 1.4):

1. C# uses namespace to organize the class by "using" keyword. Not like Java's package, C#'s namespace is purely logical without any implication of file/folder relation.

2. No "throws" in C# since C# doesn't have checked exceptions. C# only handles exception when it's actually thrown (not may be thrown). While in Java you must try-catch a potential exception or throws it explicitly, otherwise your code won't compile.

3. C# has "internal" and "protected internal" access modifiers. You can define a class with more granular scale.

3. No primitive type in C#. All C# types are rooted from System.Object. Following code is fine in C# but not in Java:
ArrayList list = new ArrayList
list.Add(123); // Java compile error
int
number = (int)list[0]; // Java compile error
Type
type = number.GetType(); // Java compile error

5. C# property is more intuitive than Java's accessor methods.

6. C# has "struct" while Java doesn't. .NET will put structs in stack instead of heap.

7. C# has "virtual" functions and you have to use "override" modifier explicitly to override a method in subclasses. A "new" function in C# creates a new method with same signature in subclasses, which is only visible in that specific class. Java doesn't have "virtual", "override" and "new" function modifiers. Function is picked based on class type checking.

8. C# doesn't have "final" constants but it has "const" and "readonly" for constant declaration. The difference between "const" and "readonly":
const
  • Can't be static.
  • Value evaluated at compile time.
  • Initialized at declaration only.
readonly
  • Can be static or instance.
  • Value evaluated at run time.
  • Declaration or initialized in the constructor.

9. C# has delegate - a type-safe method pointer. This delegate is very useful from my opinion. You can do interesting things similar to C/C++ pointers. Java doesn't have equivalent function.

10. Passing by values is default in C#. In addition C# has option to pass by references using keyword of "ref" or "out" (you have to initialize the "out" parameters). You can not pass by references in Java (for objects, Java creates a copy of parameter pointing to the same object in the heap, which leads to confusion in some cases).

Looks like C# is more powerful than Java at a glance, or just some syntax sugar you would argue?

Friday, October 08, 2004

HPCBench Now Open Source

Part of my work for High Performance Computing (HPC) analysis, I wrote a C/MPICH toolkit named HPCBench to evaluate the network performance for Linux-based clusters. Now it becomes an open-source project in SourceForge (http://hpcbench.sf.net).

Overview

Hpcbench is a Linux-based network benchmark evaluating the high performance networks such as Gigabit Ethernet, Myrinet and QsNet. Hpcbench measures the network latency and achievable throughput between two ends. Hpcbench is able to log the kernel information for each test, which includes the CPU and memory usage, interrupts, swapping, paging, context switches, network cards' statistics, etc.

Hpcbench consists of three independent packages that test UDP, TCP and MPI communications respectively. A kernel resources tracing tool "sysmon" is also included, whose output is similar to that of vmstat, but has more information of network statistics.

Programming language: C, MPI.
Recommended OS and compiler: Linux kernel 2.4 and gcc.

Features

UDP communication:

  • Microsecond resolution
  • Roundtrip time test (UDP ping)
  • Throughput test
  • Unidirectional and Bidirectional test
  • UDP traffic generator (can run in single mode)
  • Fixed size and exponential test
  • Log throughputs and process resource usage of each test
  • Log system resources information of client and server (Linux only)
  • Create plot configuration file for gnuplot
  • Configurable message size
  • Other tunable parameters:
    • Port number
    • Client and server's UDP socket buffer size
    • Message size
    • Packet (datagram) size
    • Data size of each read/write
    • QoS (TOS) type (Pre-defined six levels)
    • Test time
    • Test repetition
    • Maximum throughput restriction (Unidirectional and UDP traffic generator)

TCP communication:

  • Microsecond resolution
  • Roundtrip Time test (TCP ping)
  • Throughput test
  • Unidirectional and Bidirectional test
  • Blocking and non-blocking test
  • Fixed size and exponential test
  • Linux sendfile() test
  • Log throughputs and process resource usage of each test
  • Log system resources information of client and server (Linux only)
  • Create plot configuration file for gnuplot
  • Configurable message size
  • Other tunable parameters:
    • Port number
    • Client and server's TCP socket buffer (window) size
    • Message size
    • Data size of each read/write
    • Iteration of read/write
    • MTU (MSS) setting
    • TCP socket's TCP_NODELAY option setting
    • TCP socket's TCP_CORK option setting
    • QoS (TOS) type (Pre-defined six levels)
    • Test time
    • Test repetition

MPI communication:

  • Microsecond resolution
  • Roundtrip Time test (MPI ping)
  • Throughput test
  • Unidirectional and Bidirectional test
  • Blocking and non-blocking test
  • Fixed size and exponential test
  • Log throughputs and process resource usage of each test
  • Log system resources information of two processes (nodes) (Linux only)
  • Create plot configuration file for gnuplot
  • Tunable parameters:
    • Message size
    • Test time
    • Test repetition

Monday, August 02, 2004

Linux Tunneling

Some notes about using SharcNet nodes with ssh/tunneling.

Linux Tunneling
If pop3 server is sshd enabled:
% ssh -f -N -L 1234:localhost:110 user@POP3_server
% telnet localhost 1234
Access web server behind firewall if the web server is accessible through ssh:
% ssh -L 8080:localhost:80 129.100.19.33
When there is a ssh gateway such as gate.csd.uwo.ca:
% ssh -f -N -L 5678:129.100.19.34:80 huang@gate.csd.uwo.ca
% telnet localhost 5678 // Or open we bsite by: http://localhost:5678
Linux Reverse ssh tunnel
When only 129:100.19.34 can ssh to cat.sharcnet.ca:
% ssh -R 5678:localhost:22 cat.sharcnet.ca
Cat ssh to 129.100.19.34 : % ssh -p 5678
script:
   #!/bin/sh
# $COMMAND is to create the reverse ssh tunnel
COMMAND='ssh -N -R 5678:localhost:22 cat.sharcnet.ca'
# Is the tunnel up?
CHECK_TUNNEL=`ps -ef args | grep "$COMMAND" | grep -v grep`
# If the tunnel is not up, create the tunnel
if [ -z "$CHECK_TUNNEL" ] ; then
$COMMAND
fi
Make 129.100.19.33 web service accessible via 129.100.19.34:
(in 129.100.19.34) % ssh -fNR 8080:129.100.19.33:80 cat.sharcnet.ca
(in cat.sharcnet.ca) http://localhost:8080/a.html
Remote X tips: (if ssh -X not work)
1. Disable firewall: # /etc/init.d/iptables stop
2. Run: % ssh -R 6001:localhost:6000 huang@labmachine
3: After logon : % export DISPLAY = ":1"

Windows tunneling tips:
Access windows RDP behind firewall (such as gate.csd.uwo.ca) through Secure SSH client:
Connection: gate.csd.uwo.ca (Port 22, check "Request tunnels only")
Tunneling: Add RDP, Type->TCP, Listen Port->3456, Destination Host->129.100.19.34, Destination Port->3389
After connecting to gate.csd.uwo.ca, open Remote Desktop Client with host: localhost:3456.

Saturday, July 10, 2004

Gmail is Awesome

Last week I luckily got a gmail invitation and created a new account for myself. I have been played it around since then. It's super clean, fast and I love it!

Hotmail, Yahoo Mail, along with many other free email providers, offer only free 20-50M of mailbox. I know many corporate email systems also have a limit size of 100M for employees. Google sets the bar to 1G and it's free. It definitely is a big hit.

That makes sense. Google has expertise in building huge distributing system with commodity Linux boxes, and they could provide the same capacity with much lower price.

The only thing is the maximum size of attachment is 10M in gmail. How great it's if 20M or even 50M could be supported? I may consider using gmail as my personal online storage not just an email account.

Monday, June 21, 2004

Performance Analysis of High Performance Computing Networks

After a lot of writings, reviews, rewriting, my thesis is finally completed! Thanks Dr. Bauer and Dr. Katchabaw's help.

(Oct. 2004 updated). The full thesis can be downloaded here.

Following is the table of context of my work:

Network Performance Measurement and Analysis in High Performance Computing Environments

Chapter 1 Introduction.

Chapter 2 Background. 3
2.1 HPC history and Its Convergence to Cluster Computing.
2.2 HPC networking.
2.2.1 High Performance Network Technologies.
2.2.2 Networking of HPC Clusters.
2.3 Message Passing Interface (MPI
2.3.1 MPI Introduction.
2.3.2 MPICH.
2.4 Job Management System.
2.4.1 Goals of JMS.
2.4.2 LSF (Load Share Facility).
2.5 File Systems in HPC Clusters
2.5.1 Storage Networking.
2.5.2 Cluster File Systems.
2.5.3 Network Storage in SHARCNET.
2.6 Test-bed specifications

Chapter 3 Implementation of Hpcbench.
3.1 A Survey of Network Measurement Tools.
3.2 Metrics.
3.3 Communication Model.
3.4 Timers and Timing.
3.5 Iteration Estimation and Communication Synchronization.
3.6 System Resource Tracing.
3.7 UDP Communication Measurement Considerations.
3.8 An overivew of Hpcbench.

Chapter 4 Investigation of Gigabit Ethernet in HPC Clusters.
4.1 A Closer Look at Gigabit Ethernet
4.1.1 Protocol Properties.
4.1.2 Interrupts Coalescence and Jumbo Frame Size.
4.1.3 Data Buffers and Zero-Copy Technique.
4.2 Network Performance Analysis of Gigabit Ethernet
4.2.1 Examining Network Protocols Communication Internal
4.2.1.1 Alpha SMP Architecture.
4.2.1.2 Intel Xeon SMP Architecture.
4.2.2 Network Performance vs. Computer Performance.
4.2.3 Blocking and Non-blocking Communication.
4.2.4 Local Communication.
4.2.5 Network Protocols Latency.
4.2.6 TCP/IP Communication Throughput
4.3 A Comparison with Myrinet and Quadrics Interconnects

Chapter 5 Conclusions and Future Work.
5.1 Summary and Conclusions
5.2 Future Work.

Reference
94. 106

Tuesday, April 06, 2004

Sysmon - A Linux Tool to Monitor System Resources

I need to check system resources very often in my research work. Many tools out there but none satisfies my requirement. Instead of keep searching in Internet, I wrote my own and I am quite happy of what it does. I called it Sysmon.

So what's Sysmon anyway? In short, Sysmon is a lightweight Linux-based system resource tracing tool, as vmstat does, but has more information. The output includes the CPU/memory usage, swapping/paging, interrupts and each network card's statistics, which includes interrupts to kernel, packets and bytes that received and sent in a specified interval. Sysmon can run as a daemon and log the system information for a long period. Help menu:

Usage: sysmon [-hwWbk] [-i interface-name] [-r repeat] [-t test-interval] [-T test-time]
[-h] Printout help messages.
[-w] Write all results to a file. Disable by default.
[-W] Write statistics of each network device to separate files. Disable by default.
[-b] Background (daemon) mode. Only valid when write option is defined.
[-k] Kill the sysmon background process (daemon). Disable by default.
[-i interface-name] Define the network device name (e.g. eth0). Monitor all if no interface defined.
[-r repeat] Repetition of monitoring. 10 times by default.
[-t test-interval] The interval (sample time) between each tracing in seconds. 2 seconds by default.
[-T test-time] The duration of system monitoring in minutes. Valid only write option defined.
[-o output] Specify the output (log) filename. Implies the write option.
Note: Default logfile has format of host-start-time.log if write option (-w) is defined.

Use "ifconfig" to check the network devices in your computer.
Possible names: eth0, wlan0, elan0, etc (defined by NETNAME in util.h). loop is for loopback address.
Example 1 (Monitor all network devices, very long format): % sysmon
Example 2 (Only monitor eth0): % sysmon -r 10 -t 2 -i eth0
Example 3 (Log every 10 minutes for one week, run as daemon): % sysmon -bw -i eth0 -t 600 -T 10080
Output format:
Network information: [interrupts] [recv-packets] [recv-bytes] [sent-packets] [sent-bytes]

Sysmon is written with C. Its source code can be downloaded here.

Tuesday, March 16, 2004

MPICH Cluster Setup

This is a test to setup a cluster with two nodes using my home machines.

/etc/hosts (Redhat 9.0 with kernel 2.4.20) files:
Dell Inspiron 8100 (master node): 192.182.1.2 node1
Dell Dimension L600 (secondary node): 192.182.1.3 node2

Download the MPICH 1.2.5.2 from http://www-unix.mcs.anl.gov/mpi/mpich/ , follow the instruction to install on both machines. MPICH uses rsh or ssh to communicate with each other. The default is rsh. If you like to use ssh (secure shell) instead, you should configure with following parameters in the MPICH install directory:

[root]# ./configure --with-device=ch_p4 --prefix=/usr/local/mpich --rsh=ssh
[root]# make

After installation, add the /mpich_install_dir/bin and /mpich_install_dir/util to your $PATH environment. To let the master node ( laptop node1) know the other secondary nodes, add all nodes in the file /mpich_install_dir/util/machines/machines.LINUX:

[huang]$ cat machines.LINUX
# Change this file to contain the machines that you want to use
# to run MPI jobs on. The format is one host name per line, with either
# hostname
# or
# hostname:n
# where n is the number of processors in an SMP. The hostname should
# be the same as the result from the command "hostname"
#localhost.localdomain
node1
node2

To enable rsh (remote shell), edit the /etc/xinetd.d/rsh, change the line of "disable = yes" to "disable = no". To be convenient, I also enable the rlogin service. After the modification, you have to restart the xinetd daemon:

[root]# /etc/rc.d/init.d/xinetd restart

To let the node1 (master node) be able to run the programs in node2 automatically without password prompt, add .rhosts file in user's home directory of node2:

[huang] $ cat ~/.rhosts
node1 huang

Also, the /etc/hosts.allow and /etc/hosts.deny files must be correctly configured to allow the rsh service. For simplicity reason, I add following line on the /etc/hosts.allow file to accept all services between two machines:

ALL: node1 node2 192.182.1.0/255.255.255.0, 127.0.0.1

To allow the super user root to use the rsh and rlogin services, add another line on file /etc/securetty:

rsh, rlogin, rexec, pts/0, pts/1

The authentication file /etc/pam.d/rsh should also be modified:

[root]# cat /etc/pam.d/rsh
#%PAM-1.0
# For root login to succeed here with pam_securetty, "rsh" must be
# listed in /etc/securetty.
auth sufficient /lib/security/pam_nologin.so
auth optional /lib/security/pam_securetty.so
auth sufficient /lib/security/pam_env.so
auth sufficient /lib/security/pam_rhosts_auth.so
account sufficient /lib/security/pam_stack.so service=system-auth
session sufficient /lib/security/pam_stack.so service=system-auth

We could verify the rsh service in master node (node1):

[huang]$ rsh node2 "ps -ef"

Then the running processes in node2 will be showed on node1. Now it's ready to run parallel programs. There are some sample programs in /mpich_install_dir/examples/basic directory, enter the directory and compile the source code with command make (in both machines), e.g., cpi is MPI program to compute the PI value:

[huang]$ mpirun -np 2 cpi
Process 0 of 2 on node1
pi is approximately 3.1415926544231318, Error is 0.0000000008333387
wall clock time = 0.001943
Process 1 of 2 on node2

Make sure the executable files in each machine must be in the same directory structure. We could also specify a configure file instead of using the default machines.LINUX configuration:

[huang]$ cat my.conf
node1 0 /home/huang/cpi
node2 1 /huang/cpi
[huang]$ mpirun -p4pg my.conf cpi
Process 0 of 1 on node1
pi is approximately 3.1415926544231318, Error is 0.0000000008333387
wall clock time = 0.002097
Process 1 of 2 on node2
P4 procgroup file is my.conf.
[huang]$

Enjoy the power of parallel computing!

Thursday, March 11, 2004

Wireless Setup (WPC11V4) in RedHat Linux

Occasionally I worked in Middlesex college with my Dell Inspiron 8100 notebook, but I couldn't get the wireless connection there with my Linux bootup (Redhat 9.0 with kernel 2.4.20). It's Linksys Wireless-B network card (WPC11 V4). Notice the WPC11 V4 network card has different chipset (Realtek 8180) from previous models that are based on prism2. Getting some wireless cards to work in Linux is not a trivial thing, and I spent a couple of days fiddling around how it work. A good link about wireless LAN resources for Linux comes from Jean Tourrilhes' excellent wireless collection.

Go to Realtek's dowload website, search for 8180L driver. There is one for Linux kernel 2.4.20. Download and unzip it. Compile it as a root user, there will be a driver file named "rtl8180-24x.o" created when there were no errors. If there were something wrong, it might be caused by a messed up kernel, or source that doesn't match the kernel you are running. You have to download a new kernel (2.4.20-8) and compile the kernel. When the driver file is created, copy it to the system's module library:

[root]# cp rtl8180_24x.o /lib/modules/`uname -r`/kernel/drivers/net/wireless/
[root]# cardctl insert
[root]# depmod -ae
[root]# modprobe rtl81880_24x
[root]# cardctl ident
Socket 0:
no product info available
Socket 1:
product info: "Realtek", "Rtl8180"
manfid: 0x0000, 0x024c
function: 6(network)
[root]#

Now the device is recognized. To boot it up in the wireless network, we have to do some configuration work. Here is my script to enable the wireless card:

[huang]$ cat /etc/init.d/wlanup
# Load wireless lan driver
#/sbin/insmod -f rtl8180_24x.o
/sbin/modprobe rtl8180_24x

# Work as AP mode & Assign SSID and operation channel.
# Channel 1, 2, 10 are working fine in UWO
/sbin/iwpriv wlan0 wlan_para ssid=uwo
/sbin/iwpriv wlan0 wlan_para ssid2scan=uwo
/sbin/iwpriv wlan0 wlan_para channel=2

# Configure WEP. UWO doesn't use it, a "blue socket" instead
/sbin/iwpriv wlan0 wlan_para encmode=off
/sbin/iwpriv wlan0 wlan_para wepmode=off

# Configure debugging message
/sbin/iwpriv wlan0 msglevel 0


# Enable wireless lan driver
/sbin/iwpriv wlan0 enable
sleep 2

# Get IP address from DHCP server
/sbin/dhclient -1 -q -lf /var/lib/dhcp/dhclient-wlan0.leases \
-pf /var/run/dhclient-wlan0.pid wlan0
echo "$(/sbin/ifconfig wlan0)"
[huang]$

Notice in UWO's campus wireless network, the WEP (Wired Equivalent Privacy) is disable, instead, the school's username and password are used for authentication. The SSID (Service Set Identifier) is lowercase "uwo". After run the wlanup script, a network IP address of the wireless card would show up if the connection is established. To shutdown the connection, another script is used:

[huang]$ cat /etc/init.d/wlandown
# Shut down wlan0 net interface
/sbin/ifconfig wlan0 down

# Disable wireless lan driver
/sbin/iwpriv wlan0 disable
# Unload module
/sbin/rmmod rtl8180_24x
[huang]$ su -
[root]# cardctl eject

Finally, we add a file named "S99wireless" with one line of "/etc/init.d/wlanup" into "/etc/rc.d/rc3.d/" directory, then the script would run automatically during Linux's booting up.

Tuesday, March 02, 2004

Resolve Hotmail Login Problem

I had a trouble when logging in some websites such as hotmail with Mozilla (Firefox).

The hardware is Motorola SB5100 cable modem and Netgear RIP614 router (firmware 4.15RC4)The systems worked properly with Sympatico and Execulink ADSL high-speed connections. After switching to Rogers Cable high speed Internet, logging on to hotmail's web-mail failed and was pending on "transferring data from server".

Solution: reduce the MTU size for the connections.

Linux: [root] # /sbin/ifconfig eth0 mtu 1418

Windows XP: Modify the Windows' Registry by command "regedit": in the tree of "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", find out the network card's entry, something like "{C42A4EA1-8C79-48F4-9309-99D7DE35D462}", add a DWORD value with name of "MTU", select "Decimal" base and input the value data of "1418"; save and quit.

A MTU size of 1418 bytes is small enough to solve the problem in most cases. Basically a MTU of 1448-1472 bytes should work for most network environment.

Wednesday, February 25, 2004

Emacs & XEmacs Guide

GNU Emacs is a free, portable, self-documenting, customizable, extensible and real-time text editor, Emacs was originally written by Richard Stallman, the founder of the GNU Project, and James Gosling, the creator of the Java language. XEmacs has evolved from the original Emacs, with more GUI and content-based formatting support. For the user-friendly interface reason, I stick to Xemacs all the time.

I found Xemacs was not convenient to use at the beginning, since I was used to the vi and it's shortcuts. However, when I became more experienced I found Xemacs much powerful than vi in most aspects. (X)Emacs is the monster of all editors! It is more than just a text editor. It is a huge and complete system for development, communications, file management, and things you wouldn't even imagine. I only know a very limit features of Xemacs.

Vi (vim) and Emacs (Xemacs) have a very different look and feel, but that's not a real reason for choosing one over the other. Vi is much smaller and loads much faster, while Xemacs is a powerful tool for complex files and software development. They were designed for different jobs, they are better at different things, and I use both of them depending on the job.

Xemacs automatically saves the files you are editing by default. The name of the autosave file is the same as the name of the file you are editing, with a sharp (#) added to the beginning and to the end. When you do a file save, Xemacs creates a backup file of name with a tilde (~) added to the end. When Xemacs starts up, it reads the file ~/.emacs or ~/.xemacs/init.el to customize the Xemacs. You could modify this file by your favorite with Lisp format, e.g. if you like your Xemacs working as a pure txt editor, add the following in the .emacs file:

(setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(setq-default transient-mark-mode t)

There are several basic concepts (environment) of Xemacs: file, buffer, window, frame, echo area (mini-buffer) and mode line. When you are editing a file on disk, Xemacs read a copy of it to initialize a buffer and write a copy of a buffer out to a file to save it; a buffer is the basic editing unit hoding the text you actually edit. You can have multiple buffers but can only edit one buffer at a time; A window is the view of a buffer while frame is the whole screen of Xemacs with all buttons at the top. You could loosely call frames as windows; the echo area is the area at the very bottom of the XEmacs screen and is used to interact with you; the mode line is above the echo area on the XEmacs screen, showing the status and what is happening in the current window.

Some tips about Xemacs:

  • without X server, "Xemacs -nw" (no window mode) will open in the terminal, "Ctrl-z" switch back to the shell and type "fg" to go back Xemacs
  • command-handling "M-x" or "Alt-x" is not available in some cases, use "Esc x" instead
  • using tab or hitting space half will try to complete the command automatically
  • "M-x indent-buffer (indent-region)" will indent the buffer (region) contents
  • "M-x set-variable RET c-basic-offset RET " can set the indent value
  • a simple .emacs file with c/c++ style setting and my simpler .emacs file
  • remote access by Ange-ftp & EFS (Emacs File System):
    Ctrl-x d RET /huang@gate.csd.ca:source/mpi.cc RET
    Ctrl-x d RET /gaul.csd.uwo.ca: RET
  • remote access by Tramp (Transparent Remote Access, Multiprotocols):
    C-x d RET /[huang@gate.csd.ca]/csd/grad/huang RET
    C-x d RET /[ssh/greatwhite.sharcnet.ca]/ RET

You can do most jobs from the menus of Xemacs. But the more efficient way for editing is using shortcuts. Below are some most commonly used commands or keystrokes:



























































































































































































































Mode




Keystroke & command




Description




basic




Ctrl-x Ctrl-f




open a file




Ctrl-x d




DirEditting mode, identical to Alt-x dired




Ctrl-x Ctrl-c




quit a file and the Xemacs




Ctrl-x Ctrl-s




save a file




Ctrl-x Ctrl-w




write to a new file




Ctrl-x Ctrl-h




get help




Ctrl-h f (i, t, k, v)




get help for functions (info, tutorial, key variables, etc..)




Alt-x speedbar




pop up a speedbar




Alt-x shell (term)




switch to a shell (terminal)




buffer & window




Ctrl-x Ctrl-b




list buffers




Ctrl-x o




switch to a buffer




Ctrl-x k




kill a buffer




Ctrl-x 3




split the window vertically




Ctrl-x 2




split the window horizontally




Ctrl-x 1




make into one window




motion




Ctrl-v




Page down




Alt-v




Page up




Ctrl-p (n)




move to Previous (Next) line




Ctrl-a (e)




move to the start (end) of the line




Ctrl-f (b)




move Forward (Backward) one character




Alt-<(>)




move to the beginning (end) of the frame




Alt-x goto-line




go to certain line




editing




Ctrl-g




abort (quit) current command




Ctrl-x u




undo




Ctrl-_




more convenient undo




Ctrl-Space (Ctrl-@)




set a mark




Ctrl-x h




select the whole frame




Ctrl-w




cut the selected area




Esc w




copy to where the mark ends




Ctrl-y




yank (paste) back whatever you copied




Ctrl-d




kill one character




Ctrl-k




kill to the end of the line




Ctrl-a Ctrl-k Ctrl-k




kill an entire line




Ctrl-u 3 Ctrl-k (d)




kill the next three lines (characters)




search & replace




Ctrl-s




search




Ctrl-r




search backwards




Esc %




begin a search and replace




!




replace all occurrences at once




Space




replace




n




skip the replace




Esc




stop the search and replace




Esc Ctrl-c




continue with the search and replace




mode




Alt-x text-mode




text-mode




Alt-x c-mode


(c++, java, tex...)




programming mode




Alt-x makefile-mode Enter




makefile mode




Alt-x overwrite-mode Enter




overwrite mode




Alt-x font-lock-mode




activate color highlighting




Alt-x auto-fill-mode




auto wrapping




Alt-x auto-save-mode




auto save




Alt-x blink-cursor-mode




blinking cursor



Saturday, February 21, 2004

Vi & Vim Guide

Vi is a small, fast and efficient text editor that is installed by default in almost any Unix or Linux system, and Vim (Vi IMproved) is an enhanced version of vi. Most people find vi somewhat hard to learn at first, but it enables fast, simple and effective editing once you get used to it. I got hooked to vi when I first worked with Sun Sparc10 workstation in 1995. Vi is extremely powerful in moving around files without touching any arrow keys. Vi operates in three modes: command mode (colon prompt), insert mode and default mode. For insert mode, press ESC and type colon to switch to command mode. Vi works in default mode after ESC is pressed in all modes (without input colon). In default mode, we are able to move around in the file, switch to insert mode or command mode.

Follow is the vi/vim commands I most use:

























































































































































































Command


Mode


Description







vi filename
default


start editing a file
:wq command


write to disk and quit ( equal to :x)
:q! command


quit without saving any changes
:e! command recover to the original without any changes
:!command command execute a command; :!sh fork a shell, Ctrl-d
to exit






h; l; k; j
default one space to the left, right; one line up,
down respectively
^; $ default the beginning or end of current line
w; e default the beginning or end of next word
Ctrl-b; Ctrl-f default one page up (backward) or down
(forward)
:number command move line with the number
Ctrl-L command clear and redraw the screen
G default move to the end of file
/string; n default search string and repeat search (next)
a; A default append from next letter or the end of current
line
i; I default insert from current position or the beginning
of current line
o; O default open new line down or up of current line
x default delete single character; 5x deletes 5
characters
dw; dd default delete word or linde; 5dw deletes 5 words and
5dd deletes 5 lines
yy default yank (copy) into buffer; 5yy copies 5 lines
into buffer
p; P default paste buffer to next or previous line
u; U default undo last change or restore the current line
:set num; :set nonum command turn on or off line numbering
:set ic; set noic command ignore (or not ignore) case when searching
ma; :'a; y'a; d'a default

command
set marker 'a' (could be 'a' to 'z') to the
current position, go to marker 'a', copy text from current position to
marker 'a' into buffer, delete text from current position to marker 'a'
:%g/^#/d;


:%s/^#//g
command delete all comment lines or uncomment all the
comment lines
:[10-20]g/hello/d;


:[10-20]v/hello/d
command delete all lines containing (or not
containing) text "hello" from line 10 to 20
:i,jd;


:'a,'bd
command delete text from line i to j or from marker
'a' to marker 'b' inclusively
:i,js/old text/new text/g command substitute "new text" for "old text" from
line i to j






:'a,'bs/old text/new text/g





command substitute texts from marker 'a' to marker
'b'
:25,30m50;



'a,'bm50;


25,30co50
command move lines 25-30 to a new position after line
50; move the text between markers to line after 50; copy lines 25-30 to
line after 50

Thursday, February 19, 2004

Commonly Used Unix/Linux Tools and Commands

















































Browserlynx, mozilla, konqueror,
nautilus
Emailpine, mutt, kmail, gnus, balsa
Download(s)ftp, wget, kget, downloader for
X
Editorpico, vi, (x)emacs, ginf(html),
kite(latex), kate
Zipzip, unzip, gzip, zcat, bzip2,
tar
PS/PDFenscript, dvips, ps2pdf, pdf2ps,
a2ps, ps2epsi, xpdf, gs, gv, ggv
Image/Graphicxv, xfig, dia, gimp, gnuplot
Instant messengerlicq, amsn, gaim
Mutimediampg123, xmms, mplayer, toaster
Office suiteabiword, kword, koffice,
openoffice
IDEglade, motor, eclipse

















































































































































































































































































Command Command line
with arguments

Description

a2ps
% a2ps input -R -B
--right-footer='%s./%s#' -o output.ps

% a2ps -r --columns=1 -B -f10 --border=no -MLetter
--pretty-print=plain -o output.ps input
arguments: -r landscape (-R
for portrait), one column per page (default is 2), -B no
header , -f10 font size, --border=no no border, -MLetter
paper size to Letter, --pretty-print=plain print mode
turning off the highlights of keywords.
% a2ps input -2 -B
--right-footer='%s./%s#' ---footer='cenfooter'
-header='test' --cen='report' -o output.ps
more arguments: $Q = Page
$p./$p# (page number for this file), %Q = Page %p./%p#
(current page number), %s. (current sheet number), %s#
(total number of sheets), $s# (number of sheets of the
current file)
% a2ps $1 --columns=2
--pretty-print=$2 --font-size=8 --header='ID: 12345' -o
$3

% a2ps typescript -2 -B --right-footer='%s./%s#'
--footer='ID: 12345' --header='Asn 1' --cen='Captured
result' -o output.ps

% a2ps main.cpp -B -R --columns=1
--right-footer='%s./%s#' --left-footer='ID: 12345'
--header='Asn 1' --cen='main.cpp' -o main.ps
different output
format

ar
% ar rs liblprint.a
lprint1.o lprint2.o lprint3.o
creat a static library
with several object files
% ar -t
/usr/lib/libm.a
show the library object
dependency of libm.a
% ar -d liblprint.a
lprint3.o

% ar -s = ranlib
delete the module
awk % ls -aRl | awk '{sum =
sum + $5} END {print sum}'
sum up and print out
the file sizes

bzcat
% bzcat
prog-2.0.patch.bz2 | patch -p0
Unzip the bzip2 file
and do the patching
cat % cat file | tr -cd b |
wc -m
count the number of "b"
in the file
% cat id.pub | ssh
huang@csd.uwo.ca "(mkdir .ssh; cd .ssh; cat>>
auth)"

% cat file | ssh host "cat >> file"
ssh could be "rsh" or
"rlogin"
cb % cb -s test.cc >
test1.cc
indent code
according to K&R style (same as indent)
% cb -j test.cc put split lines back
together

chmod
% chmod -R 755
{zhu,wu,liang}/Asn1/docs/*

% chmod -R 755 [a-k]*/Asn2/*
change the
dir/subdir's permission

col
% man find | col -b
> find.txt
output a man page
into a plain text file

crypt
% crypt key <
plaintext > encrypted

% crypt key < encrypted > plaintext
Unix command,
Linux's crypt(encrypt) is a function call

diff
% diff -Nur
prog-1.0 prog-2.0 > prog-2.0.patch

% patch -p0 < prog-2.0.patch
Make a patch

dig
% dig
@ns1.uwo.ca genome1.beowulf.uwo.ca

%
dig -x
129.100.171.47

nslookup
find % find / -name
abc -print > result 2> errout

% find / -name abc -print 2>&1
1> logfile
B shell
% (find /
-name abc -print > result) >&
errout

% find / -name abc -print >&
logfile
C
shell
% find /
-type f \( -perm -2 -o -perm -20 \)
-exec ls -lg {} \; > files-results

% find / -type d \( -perm
u=rwx,g=rx,o=rx \) -exec ls -ldg {}
\; >dir-results
find the
files or directories with specific
permission
% find
[v-z]*/A*3/ -user wang -exec rm -f
{} \;
delete
all files created by user "wang" in
the directory between "v*" to "z*",
subdir of Asn3
% find
$HOME \( -name a.out -o -name '*.o'
\) -atime +7 -ok rm {} \;
remove
all files named a.out or *.o that
have not been accessed for a week,
need to confirm for each
execution
% find .
\( -type f -a -size -10k \)
-ok exec cp {} ~/tmp/ \;
copy
small size regular files to a
directory

% for i
in `find / -name *.[ch]`; do grep
-H jiffy $i; done


find
all files with defined string. -H
prints the filename for each
match

finger % finger
@hostname
show
users' info ( some versions need a
"*" before "@")
% finger
-f | awk '{print $1}

% finger -q -f | awk '{print
"User", $1, "is logged in on TTY:",
$2}'
print
out the login users with desired
format


gcc

% gcc
-o math math.c -lm

link
the shared libary
(libm.so)


% gcc
-o math math.c -lm
--static



static link. all code of libm.a
is merged into your distributed
executable

% gcc
-E test.c > test.i
turn
off compilation phase and display
the preprocess info
% gcc
-DBUFFERSIZE=1024
-D"max(A,B)=((A)>(B)?(A):(B))"
test.c

define the constant and
macro
grep %
grep -r string rc.d/
find
string in all files in rc.d
dir/subdir recursively, the same
as "-d"
% grep
-i '^\(.\).*\1$' file
all
lines whose first letter is the
same as the last one regardless
of the case (-i =-y)
gunzip %
gunzip [-q] < file.tar.gz |
tar xvf -
the
same as Linux's "tar zxvf
file.tar.gz"
indent %
indent -bad/-st/-kr/ test.c >
newformat.c

beautify the code with different
format as cb does
kill % kill
-9 -1
Kill
all processes in the login
machine
ls % ls
-aul

access tme
lsof % lsof
| nl

% lsof -u huang
list
all open files (by specified
user)
%
lsof -i -nP | grep ssh

% lsof -i :5000

% lsof -i :smtp

% lsof -i @hotmail.com

List all open files associated
with Internet connections
%
lsof /dev/cdrom

% lsof +D /tmp

% lsof `which sendmail`

% lsof -t `which
sendmail`

Who are using these
files?


netstat


% netstat -rn
routing
table

% netstat -alp
connection
statistics

nl

% nl -ba message.log | tail
-30 | grep error
print the
message having error in the
last 30 lines of the log
file
nm
% nm -a prog

% nm -s prog
list all the
symbols of the object
file
% nm -o
/lib/* /usr/lib/*
/usr/lib/*/*
/usr/local/lib/*
2>/dev/null | grep
'atoll'
search the
libraries for the
function
% nm -ng
prog
show
external symbols and
sorted by addresses

nohup
% nohup find
/ -name abc -print >
result 2>/dev/null
&
continue
finding after logout

ps
% ps
-efww
full format
(Linux)
% /usr/bin/ps
-axf
pstree plus
ps (Linux)

rcp
% rcp
brown:hb/\* .
the same as
"scp brown:hb/* .". rcp
needs .rhosts in remote
hosts:

snm.szptt.net.cn
huang

java huang

rusers


% rusers -l
hostname
show all
users in the host
% rusers
-a
show all
host names in the
network

sed
% cat file
| sed 's/^#/;/g' >
newfile
change
comments format (shell
to lisp)
% ls *htm |
sed 's/\(.*\)htm/mv
& \1html/' |
sh
change the
extension
% sed -e
's/\(\<[A-Za-z]*[aeiou][A-Za-z]*[aeiou][A-Za-z]*\>\)/(\1)/g'
file
surround
all words containing 2+
or vowels with (),
"tea"-->"(tea)"
(<> match
words)

sh
% sh -xv
shell_script
debug the
bsh script program
(csh: % csh -xv)

tar
% tar tvf
file.tar
show all
the files in a tar
file
% tar rvf
my.tar newdir
append
files in newdir to
my.tar
% tar uvf
my.tar mydir
update
my.tar with newly
updated files in
mydir
% tar cvf -
file | gzip >
file.tar.gz
the same
as linux's "tar cvfz
file.tar.gz file"
% (cd
~huang/target; tar -xvf
- .) | (cd
~huang/backup; tar -xvf
-)

% (cd ~/target; tar
cf - .) | rsh casky "cd
~/backup; tar xf -"
backup the
files in remote
machine
tr % tr -d
"\015" < input
> ouput
remove
the ugly ending char
in text files ftped
from windows to Unix,
the same as
"dos2unix"
% cat
a.txt | cat abc
| tr '[a-zA-Z]'
'[n-za-mN-ZA-M]' >
encrypted.txt

% cat
a-encrypted.txt | tr
'[a-zA-Z]'
'[n-za-mN-ZA-M]' >
decrypted.txt
the
easiest way of
encryption

uuencode
%
uuencode a.out key
> secret.out

% uudecode
secret.out
"key"
is a decode
label

wget
%
wget -r -l 4 -np
-N
http://www.abc.com

% wget -c -L
-nH
http://www.abc.com/big.zip

% wget
--passive-ftp
ftp://abc.com/d*/*.doc

download the
contents of the
website,
recursively (-r)
with depth 4 (-l
4), page
requisite mode
(-p), not ascend
the parent
directory (-np),
enable timestamp
(-N), continue
download the
interrupted file
(-c), only get
files from
relative links
(-L), disable
long header
(-nH).
%
wget -E -k -K
-p
http://www.abc.com

% wget -r
-H -l inf
--ignore-length
-p -e
robots=off
http://www.abc.com

% wget
--http-user=huang
--http-passwd=abc
--cache=off
--cookies=off
http://www/secret

html-extension
mode (-E) is
useful for asp
and cgi pages,
link-convert
(-k) and backup
the original
version (-K,
affects -N),
enable
span-host (-H),
ignore the
bogus
"Content-Length"
headers by CGIs
(--ignore-length),
turn off the
robots
mechanism(-e
)
%
wget
--save-cookies
cookies.txt
--post-data
'user=foo&password=*'
http://www.abc.com/auth.php

% wget
--load-cookies
cookies.txt
-p
http://www.abc.com/doc/article.php

llogin to the
server and
save the
cookie file (
done only
once), then
grab the
desired
pages

who

%who -u |
sort +0 -1
-u

display the
login users
without
repeat
names

%who -u |
cut -c1-10
| sort |
uniq -c |
grep -v " 1
"

display the
users
having more
than on
terminals

xterm

% xterm +ls
-sb
-rightbar
-sl 1000 -j
-title
"dreamer"
-fn
"*-courier-bold-r-*-140-*"
-b 5
-display
0:0 -bg
black -fg
green
-geometry
80x50+10+5
&



open an
xterm with
pure
subshell
(+ls) mode,
scrollbar
(-sb) with
1000 lines
(-sl) in
the right
side
(-rightbar),
jump
scrolling
(-j), font
defined
(-fn),
black
background
(-bg) and
green
foreground
(-fg), 80
characters
per line,
50 lines,
ordinate
(10, 5)
from
upper-left
corner.
( -10-5
means x
ordinate of
10 from the
right,
y ordinate
of 5 from
the
bottom)