Ubuntu – find out the location of where a process was executed

bashprocess

I have a number of ruby processes running:

ps -A | grep ruby 
 3518 ?        00:00:12 ruby
10316 ?        00:00:00 ruby
22400 pts/5    00:00:45 ruby
23332 ?        00:00:07 ruby

I get the pid above, but I want to know WHERE these processes are in the filesystem. In other words, where they were executed.

Why do I want to know? I have a daemon running in a byobu screen and I want to know where it was executed from.

byobu new -s daemon
ls -l
  -rwxrwxr-x 1 someuser someuser   83 Jul  2 11:13 db_service.sh
cat db_service.sh
  #!/bin/sh
  RAILS_ENV=production bundle exec ruby lib/daemons/db_service_ctl start
./script/db_service.sh

So as you can see from the above bash commands, a daemon was spawned (ruby on rails daemon) from the db_service.sh shell script. So where in the filesystem was it spawned from? Can ps help me here or is there a better program in linux to find out the desired information? I am not looking for the path of the ruby installation, but rather the path at which a ruby instance was executed

Best Answer

So you got the process id, you can then look around the /proc/ virtual file system. Everything is there. For e.g.

  • /proc/23124/cwd - the current directory of process 23124
  • /proc/23124/cmdline - the full command line of the process.