python - Get path of process file -
i'm trying program needs catch full path of files being used (anywhere in system) straight example. opened file called "notify.py" whichis in
/home/miguel/dropbox/prog/python/notify/
directory.
when call
ps aux
in linux shell, process line corresponding file's process is
miguel 11798 0.7 0.4 512320 34176 pts/2 sl 22:41 0:06 gedit notify.py
which doesn't path of file opened! wanted (and have been looking hours, using ps, lsof or python's psutil) way full path of file corresponding process, is, i'd like, process, directory line referenced above.
thanks answers
you might try readlink(2)
file /proc/<pid>/exe
, should want:
$ ls -l /proc/$$/exe lrwxrwxrwx 1 aw aw 0 apr 7 00:02 /proc/11700/exe -> /bin/zsh $
but note not overly portable. should work on linux , @ least freebsd, might fail on other unices. that's reason why e.g. sshd
want's called full path, sufficient take $0
(or argv[0]
or whatever corresponds 0th command line argument) know exact location of binary. there's no portable way this.
Comments
Post a Comment