Is it possible, using ps, to determine where a process is running from?

I have two applications, both are identical and running in parallel directories, such as /app1/start.sh and /app2/start.sh. If I run ps -ef then I'm unable to tell the difference between the two

Using ps (or alternative), how can I tell that PID 123 belongs to app1?

link|improve this question

feedback

3 Answers

up vote 2 down vote accepted

Some examples:

Current process list presented in tree hierarchy and wide output (showing the full command line arguments and not cutting them after X characters) ps -auxwwwf

Command pstree, show all processes and their process id's: pstree -ap

Or, if you are only interested in PIDs: pgrep -f app1 would list you all the PIDs for the processes matching pattern app1 somewhere along their name, command line arguments or path.

link|improve this answer
pgrep works for me. I'll have to predefine which PIDs are excluded from killing, but that'll work. thanks – James.Elsey Nov 10 '10 at 10:54
Great. :) Remember, there's also pkill which works the same way than pgrep, but instead of grep it kills. – Janne Pikkarainen Nov 10 '10 at 10:58
feedback

Also look at the /proc/ filesystem. In /proc/*pid* you have:

  • exe which is a symlink to the executable binary. In case of a script, this is the interpreter (/bin/bash) not the script.
  • cwd which is a symlink to the current directory of the process
  • cmdline which is a NUL separated representation of the command line

you also have a list of current file descriptors. I find /proc/*pid*/fd/255 useful in bash scripts - it's a symlink to the script itself.

ps looks at /proc/ to find info, so there may be some magic incantation of flags that shows some of these - look at ps -o

link|improve this answer
feedback

Try

ps auxf

This gives you the hierarchy of the processes.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.