Unix File Extension

This useful little snippet can be used to find the unique list of extensions for all files in a directory and all its subdirectories.  I can never remember the precise awk incantation for this:

$ find . -type f | awk -F. '{print $NF}' | tr '[:upper:]' '[:lower:]' | sort -u

Longest Interactive Command Yet

This is perhaps the longest command I’ve ever entered on the interactive command line:

[113 sengelha@centosdev-vm]% cd modules/puppet && git init && git add --all 
&& git commit -m "Initial Commit" && git remote add origin https://xxxxxxx@x
xxxxxx/scm/PM/puppet.git && git push origin master && cd ../.. && git rm -r
modules/puppet && rm -rf modules/puppet && git submodule add https://xxxxxxx
/scm/PM/puppet.git modules/puppet && git commit -m "Move puppet to submodule
" && git push

It moves a Puppet module to its own, separate git project and sets up a Git submodule reference to the moved module.

Don’t Forget to Reap your Zombies

I recently received a bug report for my quick-and-dirty TCP debugging tool tcpconndbg where it was creating a large number of zombie processes. The person who filed the bug, Peter Viskup, was even kind enough to send a patch. While this is old news to anyone with extensive Unix programming experience, always remember the following:

If you create a child process using fork(), you must either:

  1. Explicitly retrieve the child process’s exit code using one of the wait() functions (e.g. waitpid())
  2. Tell the system that you aren’t interested in the child process’s exit code by using either:
    1. sigaction() with the SA_NOCLDWAIT parameter (preferred)
    2. signal(SIGCHILD, SIG_IGN); (for systems which do not support sigaction())

As I fixed this bug, I realized I hadn’t looked at tcpconndbg in 5 years. My how programming style changes…