Kepler's
Unix Tips
This pages contains some of my UNIX
tips that you may find it useful and interesting.
Command tips
Followings are some of my favour
commands to use.
How to find out all the files
containing a particular string under a particular directory ?
# find <directory> -print -exec grep <string>
"{}" \;
How to remove those Ctrl-H
characters output by the man pages, so that you can vi the output of man
command ?
Try the following
script and name it as rmctlh :
(ctrlh=`echo '\010'` ; sed "s/.$ctrlh//g")
Change mode of rmctlh to be user executable, then use it as a filter :
e.g. $ man man | rmctlh
If I just want to remove some
of the files under a particular directory, how can I have Unix prompt me
to select which one to delete ?
Try : $ find
<directory> -ok rm "{}" \;
How can I kill all the process
with a particular name ?
By making use of the
pipeline and some filter features of Unix, try :
$ ps -ef | grep <process name> | awk '{print $2}' | xargs kill
How to find out all the same
hard links of a particular file ?
First
is to find out the inode # by :
# ls -i
Then use following to find out all the files with that inode # :
#
ncheck
<inode-#>
Which file I should examine
if setld fail ?
Try checking /var/adm/smlogs/setld.log which may have information
that you will be interested in.
How to
reset the X server ?
Add the -terminate
option in the /var/X11/Xserver.conf , then kill the Xserver process
(/usr/bin/X11/X). The xdm will automatically restart the Xserver.
The Xserver will also be reset each time when you logout after adding the
above option.
How to find out the IP address
of your host ?
First
find out the interface name by :
# netstat -i
Then use following to find out the I.P. address of that interface
# ifconfig <interface>
In Solarise,
ifconfig provide a -a option which
will show all the interface information.
How to mirror two directories
?
Here
is a script that I used :
How to find out which library
contains a particular symbol ?
Here
is a simple script I use.
Performance Tuning
What happen if excessive
page in but few page out in the output of vmstat
?
Then most likely,
you have set the UBC-borrowprecent too low, thus causing the UBC pages
easily been claimed by the VM, since the UBC pages usually are unmodified,
thus why not much page out. But if they are accessed again (since hey have
been kicked out easily by the VM), then they will be loaded back again
to physical memory, causing excessive page in.
What can I do in a low memory
Xserver system if memory shortage happen ?
Try to reset
the Xserver as the space allocated to Xserver will not be freed until
the Xserver is reset.
Unix internal & advance topics
If you find the following questions interesting, I recomment the Unix Internal course which will provide more detail information to satisfy your need.
What makes traditional Unix
not a real time system ?
There are two factors
that make traditional Unix not a real-time operating system :
What is the difference between
BSD & System V Unix?
In the history of
Unix, around the late 70's. Unix branches into two different major release,
one is the System V release developed by AT&T. While the other is the
Berkeley Software Distributions (BSD) version. The BSD project was later
then to provide support for the DARPA Internet networking procotols TCP/IP,
thats why BSD socket was developed. While the System V implementation provided
the STREAMS, an IPC (inter-process communication) mechanism. The internal
memory management structure of System V was also different from the Berkeley
paging system. Besides the above major difference. The signal handling
and terminal session handling are also different between BSD and System
V.
Why we need multi-threading
in Modern Unix ?
![]()
Traditionally to support multi-programming in Unix, usually subprocesses
are used. Usually the parent process will fork different
child process to handle different things that need to be executed in parallel
in a particular task. A typical example is the internet daemon inetd
which
will fork different child process to handle different internet connections
e.g. one telnetd for each telnet session and
one ftpd for each ftp session. But whats wrong
with this approach. Since to create a sub-process is not an economic job,
its quite expressive for using system resources. e.g. allocation of process
structure and page tables in a paging system (though most modern Unix uses
absolutely lazy evaluation to allocate memory i.e. defer the allocation
of physical memory until the last moment, still it needs to allocate stack
etc.). Thus threads are introduced in modern Unix. Threads are usually
refered as light weight objects and relatively less overhead to
create. Since all the threads in a process shares the whole virtual addressing
space of that process, only different stacks (and a seperate thread structure
in the kernel for kernel thread) are need to be allocated. Its more efficient
and less expensive.
What is the WCHAN
field in the output of ps -el ?
WCHAN
is called the wait channel. When a process is going to wait for a system
resource, it'll be assigned to a wait channel, usually it'll be an address
related to the resource, and later the wakeup call will be passed with
this address to wait the process up. e.g. for reading the hard-disk, the
WCHAN
will be the address of the buffer that going to receive the data. Then
once data is arrived, the interrupt handler will use the same address to
wakeup the waiting process.
vi
=
ex ?
Try the following
if you have super user privilage.
# cd /usr/bin
# rm vi
# mv ex vi
# vi
See, vi is exactly equal to ex
! In fact, if you use the ls -i to check their
i-node number, they are the same. i.e. it means that they are hard-link
to each other. But how can they be different during execution and what's
the advantage of doing so ? Thats the advantage of using the first argument
(in fact the zero-th) in a C program. As in every C program, the zero-th
argument is the name of the file itself, by checking this argument, the
program can branch to different starting point. But why the original developer
didn't seperate them into two different programs ? The answer is for the
traditional Unix, share library is not supported. As vi
and
ex
are very popular programs that likely to be executed by different users
in the system at the same time. If they are the same executable, the kernel
will share the common text portion (i.e. executable part of the program
file) with all the users, in order to save physical memory. In fact, many
Unix programs use this tricks. Verify with passwd
and chsh program.
What is the difference of
symmetric multi-processing (SMP) and asymmetic multi-processing ?
To know more, the
Unix
Internal course will be interested to you.
What are kernel threads and
user threads ?
See the diagram.
When will be the running
process go to the kernel mode ?
What are those defunct process
shown in the output of ps ?
What are the limitations
of the traditional Unix file system ?
In the traditional
design of both s5fs (System V file system) and Berkeley's ffs (Fast Filesystem),
the inode table can only reside in only one disk (or a partition of the
disk) and the index of the inode table which points to the actual physical
data block can also only address the local disk (or partition). Thus files
cannot split over different physical disks (or partitions). Moreover Unix
are usually designed for 32 bits machines (except those early 16-bits dinosaur
machines!), thus the offset of the files passed into most of the filesystem
related system calls e.g. read, write
are usually an integer. This imposes another logical maximun for the file
size to be 31 bits (most significant bit as sign bit). Moreover, since
the inode table is something like an on disk array design, so you need
to estimate how large of the table when you first initalize your file system
by specific the inode density in the mkfs
command. Once the table is full, you don't have any way to increase it
-- only way is to backup all your files, re-initialize the filesystem and
restore all your data -- how clumsy it is ! To address the above problem,
Digital Unix introduce the Advance File System, try attend the Unix
Internel course for more detail.
What are the restrictions
of traditonal buffer cache design ?
How to use Perl to emulate
the UNIX wall command ?
Click
here for the example.