Saturday, May 24, 2014

Identify the program accessing a file on Linux

Make sure you check man page for fuser for more of the many switches which can be really handy..

wiz@cb-DOC:~$ man 1 fuser

Here we are just finding which program or thread is accessing a file, and it can be done as follows..

wiz@deb-DOC:~$ sudo fuser /var/log/syslog
/var/log/syslog:      3234 ---> pid of rsyslog (rsyslog since i'm running debian here)

and we also may use the lsof to do the same job and many more..

Make sure you check man page for lsof for many more switches which can be really handy..

wiz@cb-DOC:~$ man 8 lsof

wiz@deb-DOC:~$ lsof /var/log/syslog
wiz@deb-DOC:~$ sudo lsof /var/log/syslog
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
rsyslogd 3234 root    1w   REG    8,2    35170 7079847 /var/log/syslog

HTH

No comments:

Post a Comment