Wednesday, July 25, 2007

linux tidbit - Finding the working directory of a process

If you are working on multiple Ruby on rails apps, you will have at least 2-3 instances running on your machine at the same time. It is a chore to keep straight the port numbers with project directories (hmm maybe I should write a plugin for this :~))

I was in a similar situation where I couldn't recall why a RoR instance was running on one of the ports.

So I did a ps -auxww to get the process id of the process and then

cp> cd /proc/[process_id]/cwd
cp> pwd
/home/cpatil/....


Pretty cool!
/proc is a virtual filesystem and allows you to peek inside the OS kernel at runtime and find information about the processes running on the machine. Google for it, a one time read is a must for all linux users, young and old.
It is quite funky the way it is set up. For e.g. most files are 0 bytes and you need to do a cat to read it. Stuff like that.

No comments: