Thursday, June 11, 2009

Little Sugar: Useful commands while programming on Unix Systems

Here are a list of commands that re use file while programming on unix systems

pid = process id

ps aux | grep process_name
- to search for a given process name , generally use this to fetch pid of process

lsof -p pid
- to get all the files or file descriptors being used by the process having pid

lsof | grep file_name
- to get the list processes using a given file

sockstat | grep process_name
- to see the socket connections between a host and desinations

strace -p pid
- to see what the process is doing in general

nc hostname port
- to see data flowing from the hostname at the given portu

Tuesday, June 09, 2009

Little Sugar: Things to remember while creating a daemon

While writing a daemon on unix systems. The daemon should not be attached to any
terminals. So make sure the following things hold valid.

chdir '/'

umask 0

Map STDIN to /dev/null
Map STDOUT to your logging system
MAP STRERR to STDOUT

setsid # Make the daemon a session leader