Monday, 11 June 2012

Check witch files a process has open

This script will output a list of the files that are open by a given process:

#!/bin/bash
PROCESS=$1
log_found=`ps faux|grep -v grep|grep $PROCESS|awk '{print $2}'`
if [ "$log_found" == "" ]; then
echo "No process found"
else
echo "Open files:"
for PID in $log_found; do
#ls -l /proc/$PID/fd/ | awk '{print $NF;}'
ls -l /proc/$PID/fd/
done
fi


Possibly Related Posts

No comments:

Post a Comment