I am working on a Linux server, and I running different jobs on different node.

However, when compiling my program, I didn't set their specific name, so they are all a.out

Now I found one of the running a.out, may be not right, and want to terminated. But the Top command doesn't show the path to the executable.

enter image description here

How to do it?


You can use lsof (available for just about any Unix variant, but often not part of the default installation) to list all the files a process is using. “Using” includes open file descriptors as well as closely related concepts such as which executable the process is running. The executable has txt in the FD column, for obscure historical reasons.

$ lsof -p1234 | grep txt
a.out    1234 user15964  txt   REG  253,0  34567 /path/to/a.out

(made-up output)

On Solaris and Linux, there's a more direct way: the proc filesystem provides information about each process, including which executable it's running. (On Linux at least, that's where lsof gets its information.)

$ ls -l /proc/1234/exe
lrwxrwxrwx 1 root root 0 Feb 30 34:56 /proc/1234/exe -> /path/to/a.out

If you're looking for a process running a given executable, run fuser.

$ fuser /path/to/a.out
/path/to/a.out: 1234e 1239e
  • Wow, you answer provide more info. Thank you so much. I decide to accpet yours – user15964 Apr 9 '16 at 3:07

There's no general answer. Under modern Linux, you can look in /proc/$PID where $PID is the numerical process ID. You can get it out of the top output.

ls -l /proc/$PID/exe will show you where exe is a symbolic link to. That's the full path to the a.out executable.

  • Seems like that is a general answer, for Linux (which this question is tagged as).... – Wildcard Apr 8 '16 at 1:56
  • It's worth knowing that /proc/$PID/exe isn't a standard symlink. – Wildcard Apr 8 '16 at 1:57
  • But, I tried "ls -l /proc/28363/exe", it says no such file or folder – user15964 Apr 8 '16 at 1:58
  • @user15964, what OS are you using? Does ls -l /proc show anything? – Wildcard Apr 8 '16 at 1:59
  • @Wildcard yeah, ls -l /proc shows a list. I am on RedHat linux – user15964 Apr 8 '16 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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