core file location

Still no definitive answers…

In one machine, q(ulimit -c) returns 0 meaning suppressing core files. I had to run q(ulimit -c unlimited) to get my core files generated.


after fork(): threads,sockets..

–based on

The child process is created with a single thread—the one that called fork(). The entire virtual address space of the parent is replicated in the child, including the states of mutexes, condition variables, and other pthreads objects.

The very 1st instruction executed in Child is the instruction after fork() — as proven in

The child inherits copies of the parent’s set of open file descriptors, including stdin/stdout/stderr. Child process should often close them.

Special case — socket file descriptor inherited. See



bashslash escape: bash tricky rules

This is about shell interpreting the backslash sequence inside single-quote or double-quote.

Once bash does its parsing, it can pass the result to a command like perl or grep.

----Most escape sequences don't care about single-quote vs double-quote
$ echo "msgType\t"

$ echo "msgType\b"

# \b is meaningful in perl regex 🙂

----double backslash -- single-quote is simpler than double-quote
$ echo 'msgType\\'

$ echo "msgType\\"

----single quote within single-quoted string is very tricky:
$ echo 'msgType\'\' 

# in the above, the last \' is a second token, a single-char string.

$ echo $'msgType\''  # dollar sign is crucial

$ echo 'msgType\'' # somehow doesn't work without $

simple bash script to end in exec #home-made

In this script, we check if the login is rpmadmin. If not, su to rpmadmin and run the same script!

Useful technique.

if [ $(whoami) != "rpmadmin" ] ; then
  set -x
  exec su rpmadmin $0

# 5 other steps....
sudo /var/opt/rpmadmin/bin/ ${pn}-?.?.?-?.rhel6.3.x86_64.rpm

bash: simplest bool flag based on hostname match

  • Note the quotes and the star in hostname check
  • Note no quotes needed around $isUK
[[ $(hostname) == "rtdevfrh"* ]] && isUK=1
[[ -z $isUK ]] && echo not in UK
[[ -n $isUK ]] && echo in UK

my .vimrc file

set nu
set bg=dark

"map the 'v' keystroke to mean 'save file unconditionally'
map v :w!

from within bash script1 get script1’s dirname full path

readlink -f $0 # requires more steps, but takes care of symlinks. Seldom needed.

echo BASH_SOURCE gives "${BASH_SOURCE[0]}"

dirname "${BASH_SOURCE[0]}"
echo .. above dirname is often a relative path

fullpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo fullpath is $fullpath # fairly reliable one-liner, provided the script itself isn't a symlink

## vi (+less) cheatsheet

  • ~~~~ command mode #roughly ranked
  • [3] dt — “dta” delete until the next “a”
  • [2] 9s — wipe out 9 characters (including current) and enter insert-mode. Better than R when you know how many chars (9) to change
    • to delete 5 characters … there is NO simpler keystroke sequence
  • R — Overwrite each character one by one until end of line. Useful if the replacement content is similar to original?
  • Ctrl-R to re-do
  • cw — wipe out from cursor to end of word and puts you into insert mode
    • c2w or 2cw
  • :se list (or nolist) to reveal invisible chars
  • C — wipe out from cursor to END of line and puts you into insert-mode
  • capital O — open new line above cursor
  • A — to append at END of current line
  • from inside q(LESS), type a single “v” to launch vi

–paging commands in vi and less

  • jump to end of file: capital G == in both vi and LESS
  • jump to head of file: 1G == in both vi and LESS
  • page dn: Ctrl-f == in both; LESS also uses space
  • page up: Ctrl-b == in both; LESS also uses b

[3/4] means vi receives 3 keystrokes; we hit 4 keys including shift or ctrl …


vi on multiple files

[3/4] means vi receives 3 keystrokes; we hit 4 keys including shift or ctrl …

–“split” solution by Deepak M

vi file1 # load 1st file

  • :sp file2 # to show 2nd file upstairs
  • :vsp file3 # to show 2nd file side by side
  • You end up with  — file2 and file3 side by side upstairs, and file1 downstairs!
  • [2/3] ctrl-ww # To move cursor to the “next” file, until it cycles back

–the q( :e ) solution

vi file1 # load 1st file

  • :e file2 # to put 2nd file on foreground
  • [1/3] ctrl-^ — to switch to “the other file”
  • This solution is non-ideal for moving data between files, since you must save active file before switching and you can’t see both files

–editing 3 or more files

  1. vi file1 file2 file3
  2. q(:n) to switch to next, q(:N) for previous…
  3. q(:args) shows all files
  • –Suppose now you are at file2.
  • q(:e file4) works. q(^) will toggle between file2 and file4
  • However, q(:n :N  :args) only work on the original list, not the new files from q(:e)

q(:n :N ^) always shows the current filename in status bar:)