Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers 3

up vote 5 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.

share|improve this answer
    
pgrep works for me. I'll have to predefine which PIDs are excluded from killing, but that'll work. thanks –  user155695 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
add comment

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

share|improve this answer
add comment

Try

ps auxf

This gives you the hierarchy of the processes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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