Pages

Showing posts with label SHELL. Show all posts
Showing posts with label SHELL. Show all posts

Wednesday, July 27, 2011

diff OUTPUT FORMAT

Showing Differences Without Context

The "normal" diff output format shows each hunk of differences without any surrounding context. Sometimes such output is the clearest way to see how lines have changed, without the clutter of nearby unchanged lines (although you can get similar results with the context or unified formats by using 0 lines of context). However, this format is no longer widely used for sending out patches; for that purpose, the context format (see section Context Format) and the unified format (see section Unified Format) are superior. Normal format is the default for compatibility with older versions of diff and the Posix standard.

Detailed Description of Normal Format

The normal output format consists of one or more hunks of differences; each hunk shows one area where the files differ. Normal format hunks look like this:

change-command
< from-file-line < from-file-line... --- > to-file-line
> to-file-line...
There are three types of change commands. Each consists of a line number or comma-separated range of lines in the first file, a single character indicating the kind of change to make, and a line number or comma-separated range of lines in the second file. All line numbers are the original line numbers in each file. The types of change commands are:

`lar'

  • Add the lines in range r of the second file after line l of the first file. 
  • For example, `8a12,15' means append lines 12--15 of file 2 after line 8 of file 1; or, if changing file 2 into file 1, delete lines 12--15 of file 2.

`fct'

  • Replace the lines in range f of the first file with lines in range t of the second file. This is like a combined add and delete, but more compact. 
  • For example, `5,7c8,10' means change lines 5--7 of file 1 to read as lines 8--10 of file 2; or, if changing file 2 into file 1, change lines 8--10 of file 2 to read as lines 5--7 of file 1.

`rdl'

  • Delete the lines in range r from the first file; line l is where they would have appeared in the second file had they not been deleted. 
  • For example, `5,7d3' means delete lines 5--7 of file 1; or, if changing file 2 into file 1, append lines 5--7 of file 1 after line 3 of file 2.

Comparison & Merge files

http://www.chemie.fu-berlin.de/chemnet/use/info/diff/diff_toc.html

Wednesday, July 13, 2011

Error: [: = unary operator expected

# Remove all shared memory segment
ipcs -m |\
while read key shmid owner perms bytes nattch status
do
if [ $owner = $USER ]
then
echo -e "\t removing shared memory segment \"$shmid\"" 1>&2
ipcrm -m $shmid
fi
done

Error:

rmShm.sh: line 13: [: =: unary operator expected
removing shared memory segment "55443496"
rmShm.sh: line 13: [: =: unary operator expected


Fix:
if [ "$owner" = "$USER" ]

Thursday, June 23, 2011

stdin, stdout, and stderr

the integer file descriptors associated with the streams stdin, stdout, and stderr are 0, 1, and 2, respectively.

Wednesday, June 22, 2011

What is /dev/shm and its practical usage

/dev/shm is nothing but implementation of traditional shared memoryconcept. It is an efficient means of passing data between programs. One program will create a memory portion, which other processes (if permitted) can access. This will result into speeding up things on Linux.
shm / shmfs is also known as tmpfs, which is a common name for a temporary file storage facility on many Unix-like operating systems. It is intended to appear as a mounted file system, but one which uses virtual memory instead of a persistent storage device.
If you type mount command you will see /dev/shm as a tempfs file system. Therefore, it is a file system, which keeps all files in virtual memory. Everything in tmpfs is temporary in the sense that no files will be created on your hard drive. If you unmount a tmpfs instance, everything stored therein is lost. By default almost all Linux distros configured to use /dev/shm.

Nevertheless, where can I use /dev/shm?

You can use /dev/shm to improve the performance of application software or overall Linux system performance. On heavily loaded system, it can make tons of difference. For example VMware workstation/server can be optimized to improve your Linux host's performance (i.e. improve the performance of your virtual machines).
For example, if you have 8GB RAM then remount /dev/shm as follows:
# mount -o remount,size=8G /dev/shm
To be frank, if you have more than 2GB RAM + multiple Virtual machines, this hack always improves performance.
# mount -t tmpfs -o size=5G,nr_inodes=5k,mode=700 tmpfs /disk2/tmpfs
Above will give you tmpfs instance on /disk2/tmpfs which can allocate 5GB RAM/SWAP in 5K inodes and it is only accessible by root.

Friday, June 17, 2011

POSIX Semaphores

The potential learning curve of System V semaphores is much higher when compared to POSIX semaphores. This will be more understandable after you go through this section and compare it to what you learned in the previous section.

To start with, POSIX comes with simple semantics for creating, initializing, and performing operations on semaphores. They provide an efficient way to handle interprocess communication. POSIX comes with two kinds of semaphores: named and unnamed semaphores.

Thursday, June 9, 2011

"Make'' Your Programs

A General Overview


make is a command generator. Using a description file and some general templates, it creates a sequence of commands for execution by the UNIX shell. These commands commonly relate to the maintenance of the files comprising a software development project. Here, ``maintenance'' refers to a whole array of tasks, ranging from status reporting and the purging of temporary files, to building the final, executable version of a complex group of programs.

The description file is usually named as Makefile or makefile. After this file is created, one can run the program make to make executables as described in the makefile:

make