Posts

Showing posts from April, 2006

How to create a core dump

>gcc -o null.exe null.c ; null.exe //c program that I found on the net that will cause a core dump //file null.c int a (int *p); int main (void) { int *p = 0; /* null pointer */ return a (p); } int a (int *p) { int y = *p; return y; } Here are two other ways to create core dumps >gcc -o crash.exe crash.c ; ./crash.exe //file crash.c int main(int argv,char *argc) { int *numdie; numdie[23] = 23; } >gcc -o sleep.exe sleep.c | ./sleep //file sleep.c #include int main(int argv,char *argc) { sleep(10000); } In another terminal >ps aux | grep sleep.exe replace pid with the pid you find from the previous command pid will be a number in the second column >kill -SIGV pid if you see an error like No core dump was created >Bus error An error like this means a core dump was created >Bus error (core dumped) >ulimit -c #will print the current core file max size >ulimit -c unlimited to make it unlimited #ulimit # -c The maximum size of core files c

Is It "2>&1 file" or "> file 2>&1"? Why?

8.13 Is It "2>&1 file" or "> file 2>&1"? Why? One of the common questions about the Bourne and Korn shells is why only the second command will redirect both stdout and stderr (13.1) to a file: $ cat food 2>&1 >file cat: can't open food $ cat food >file 2>&1 $ Although lots of sh manual pages don't mention this, the shell reads arguments from left to right. 1. On the first command line, the shell sees 2>&1 first. That means "make the standard error (file descriptor 2) go to the same place as the standard output (fd1) is going." There's no effect because both fd2 and fd1 are already going to the terminal. Then >file redirects fd1 (stdout) to file. But fd2 (stderr) is still going to the terminal. 2. On the second command line, the shell sees >file first and redirects stdout to file. Next 2>&1 sends fd2 (stderr) to the same place fd1 is going - that's to the file. And th

bash loop through parameters

for i in $* do #will echo all the variable passes as parameters echo $i done

bash getopts example

while getopts ":c:sd" Option # Initial declaration. # c, s, and d are the flags expected. # The : after flag 'c' shows it will have an option passed with it. do case $Option in # w ) CMD=$OPTARG; FILENAME="PIMSLogList.txt"; TARGET="logfiles"; ;; s ) PORT=20 ;; d ) DEBUG=true ;; c ) CMD=$OPTARG ;; * ) echo "Not recognized argument"; exit -1 ;; esac done shift $(($OPTIND - 1))

to install and remove System-V style init script links

update-rc.d is the Debian utility chkconfig is the Red Hat utility

Debian package commands

# apt-get check # update cache and check for broken packages $ apt-cache search pattern # search package from text description $ apt-cache policy package # package priority/dists information $ apt-cache show -a package # show description of package in all dists $ apt-cache showsrc package # show description of matching source package $ apt-cache showpkg package # package information for debugging # dpkg --audit|-C # search for partially installed packages $ dpkg {-s|--status} package ... # description of installed package $ dpkg -l package ... # status of installed package (1 line each) $ dpkg -L package ... # list filenames installed by the package Referenced from http://www.debian.org/doc/manuals/reference/ch-package.en.html

Check for a pid in bash with out pgrep

pid_check() { local PID=$1 local i for i in `ps ax | awk 'BEGIN { FS = "[ \t]+" } ; { print $1 ;print $2 }'| grep $PID`; do if [ "$PID" -eq "${i:=''}" ] ; then echo "Matched $PID" return 0; fi echo "$i" done return 1; } pid_check 1068

New Years Picture

Image
Here is a good picture from new years

Just passed the 100 post mark

Just passed the 100 post mark, see you at the 200 post mark