Skip to main content
deleted 76 characters in body
Source Link
ilkkachu
  • 148.2k
  • 16
  • 268
  • 441

/proc/$PID/exe seems to be what you're looking for: (proc(5):

/proc/[pid]/exe
Under Linux 2.2 and later, this file is a symbolic link containing the actual pathname of the executed command. This symbolic link can be dereferenced normally; attempting to open it will open the executable.

So, simply:

$ /bin/cat & ls -lreadlink /proc/$!/exe lrwxrwxrwx 1 itvirta itvirta 0 May 27 18:14 /proc/11335/exe -> /bin/cat*cat 

It actually follows renames on the executable file:

$/tmp$ cp /bin/cat . ; ./cat & mv cat dog ; ls -lreadlink /proc/$!/exe lrwxrwxrwx 1 itvirta itvirta 0 May 27 18:14 /proc/11304/exe -> /tmp/dog*dog 

proc(5):

/proc/[pid]/exe
Under Linux 2.2 and later, this file is a symbolic link containing the actual pathname of the executed command. This symbolic link can be dereferenced normally; attempting to open it will open the executable.

So, simply:

$ /bin/cat & ls -l /proc/$!/exe lrwxrwxrwx 1 itvirta itvirta 0 May 27 18:14 /proc/11335/exe -> /bin/cat* 

It actually follows renames on the executable file:

$ cp /bin/cat . ; ./cat & mv cat dog ; ls -l /proc/$!/exe lrwxrwxrwx 1 itvirta itvirta 0 May 27 18:14 /proc/11304/exe -> /tmp/dog* 

/proc/$PID/exe seems to be what you're looking for: (proc(5)

/proc/[pid]/exe
Under Linux 2.2 and later, this file is a symbolic link containing the actual pathname of the executed command. This symbolic link can be dereferenced normally; attempting to open it will open the executable.

So, simply:

$ /bin/cat & readlink /proc/$!/exe /bin/cat 

It actually follows renames on the executable file:

/tmp$ cp /bin/cat . ; ./cat & mv cat dog ; readlink /proc/$!/exe /tmp/dog 
Source Link
ilkkachu
  • 148.2k
  • 16
  • 268
  • 441

proc(5):

/proc/[pid]/exe
Under Linux 2.2 and later, this file is a symbolic link containing the actual pathname of the executed command. This symbolic link can be dereferenced normally; attempting to open it will open the executable.

So, simply:

$ /bin/cat & ls -l /proc/$!/exe lrwxrwxrwx 1 itvirta itvirta 0 May 27 18:14 /proc/11335/exe -> /bin/cat* 

It actually follows renames on the executable file:

$ cp /bin/cat . ; ./cat & mv cat dog ; ls -l /proc/$!/exe lrwxrwxrwx 1 itvirta itvirta 0 May 27 18:14 /proc/11304/exe -> /tmp/dog*